我不知道问题出在哪里。
监听器没有捕获onRinging
事件(因此我可以决定是接受还是拒绝来电)。
在清单中是这样的:
<uses-permission android:name="android.permission.USE_SIP" />
主要活动onCreate
中的是:
IntentFilter filter = new IntentFilter();
filter.addAction("android.SipDemo.INCOMING_CALL");
callReceiver = new IncomingCallReceiver();
this.registerReceiver(callReceiver, filter);
...
SipManager manager = SipManager.newInstance(this);
Intent i = new Intent();
i.setAction("android.SipDemo.INCOMING_CALL");
PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, Intent.FILL_IN_DATA);
manager.open(me, pi, null);
BroadcastReceiver
中的是这样的:
public void onReceive(Context context, Intent intent) {
SipAudioCall incomingCall = null;
try {
SipAudioCall.Listener listener = new SipAudioCall.Listener() {
...
@Override
public void onCallEnded(SipAudioCall call) {
// TODO Auto-generated method stub
super.onCallEnded(call);
}
@Override
public void onRinging(SipAudioCall call, SipProfile caller) {
try {
call.answerCall(30);
call.startAudio();
call.setSpeakerMode(true);
if(call.isMuted()) {
call.toggleMute();
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
WalkieTalkieActivity wtActivity = (WalkieTalkieActivity) context;
incomingCall = wtActivity.manager.takeAudioCall(intent, listener);
wtActivity.call = incomingCall;
...
我收到CallEnd
事件和onChanged
(在我结束通话后),但我没有收到onRinging
事件。
什么可能是一个问题?
日Thnx
编辑: 我改变了一切。 我把新的意图过滤器放到接收器上(粗体):
<receiver android:name=".IncomingCallReceiver" android:label="Call Receiver">
**<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>**
</receiver>
我改变了BroadcastReceiver这样的继承类(粗体):
@Override
public void onReceive(Context context, Intent intent) {
try {
**PhoneStateListener phoneListener=new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
// TODO Auto-generated method stub
Log.d("DEBUG", "Phone listener....");
String stateString = "N/A";
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
stateString = "Idle";
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
stateString = "Off Hook";
break;
case TelephonyManager.CALL_STATE_RINGING:
stateString = "Ringing";
break;
}
}
};**
WalkieTalkieActivity wtActivity = (WalkieTalkieActivity) context;
SipSession ses=wtActivity.manager.getSessionFor(intent);
**TelephonyManager telephony = (TelephonyManager) Context.getSystemService(Context.TELEPHONY_SERVICE);
telephony.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);**
...
现在我只得到IDLE状态,但仍然没有响个不停。
答案 0 :(得分:7)
SipAudioCall类的源代码中存在错误。
要解决此问题:
incomingCall = wtActivity.manager.takeAudioCall(intent, null);
incomingCall.setListener(listener, true);
答案 1 :(得分:4)
我已经实现了相同的方案来接受或拒绝sip演示中的来电。 使用两个按钮Accept和Reject创建自己的Activity(IncomingGui.java)。 在BroadcastReciever类中调用您的Activity(IncomingGui.java)来电事件。
WalkieTalkieActivity wtActivity = (WalkieTalkieActivity) context;
incomingCall = wtActivity.manager.takeAudioCall(intent, listener);
showIncomingCallGui(intent, context);
wtActivity.call = incomingCall;
然后在BroadcastReciever类
中定义以下方法 public void showIncomingCallGui(Intent intent,Context context) {
Intent incomingCall=new Intent(context,IncomingCallGui.class);
context.startActivity(incomingCall);
}
public static void answerIncomingCall(){
try {
incomingCall.answerCall(30);
incomingCall.startAudio();
incomingCall.setSpeakerMode(true);
if (incomingCall.isMuted()) {
incomingCall.toggleMute();
}
}
catch(Exception e){
System.out.println(e.toString());
}
}
public static void rejectIncomingCall(){
try {
if (incomingCall !=null) {
incomingCall.endCall();
incomingCall.close();
}
}
catch(Exception e){
System.out.println(e.toString());
}
然后在IncomingGui.java中定义“Accept”和“Reject”按钮后面的以下方法。 现在,在来电时,您将拥有自己的来电活动来接听或拒绝来电。
public void onCallAcceptButton(View view){
IncomingCallReceiver.answerIncomingCall();
}
public void onCallRejectButton(View view){
IncomingCallReceiver.rejectIncomingCall();
this.finish();
}