来电时没有响铃事件

我不知道哪里出了问题。 监听器没有捕获到onRinging事件(因此我可以决定是接受还是拒绝来电)。 在清单中是这样的:

  

在主要活动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

编辑:我改变了一切。 我把新的意图filter放到这样的接收器(粗体):

  **  **  

我改变了BroadcastReceiver这样的inheritance类(粗体):

 @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状态,但仍然没有响。

SipAudioCall类的源代码中存在错误。

要解决此问题:

 incomingCall = wtActivity.manager.takeAudioCall(intent, null); incomingCall.setListener(listener, true); 

我已经实现了相同的场景来接受或拒绝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(); }