来电时无振铃事件
我不知道哪里出了问题。 侦听器不会捕获 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
事件。 可能有什么问题? 谢谢
编辑: 我改变了这一切。 我将新的意图过滤器添加到接收器中,如下所示(粗体):
<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 状态,但仍然没有响铃。
I don't know where is a problem.
Listener doesn't catch onRinging
event (so I can decide will I accept or reject incoming calls).
in manifest is this:
<uses-permission android:name="android.permission.USE_SIP" />
in main activity onCreate
is this:
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);
in BroadcastReceiver
class is this:
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;
...
I recieve CallEnd
event and onChanged
(after I end call) but I dont recieve onRinging
event.
what could be a problem?
Thnx
EDIT :
I changed it all.
I put new intent filter to receiver like this (bold):
<receiver android:name=".IncomingCallReceiver" android:label="Call Receiver">
**<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>**
</receiver>
and I changed BroadcastReceiver inherit class like this (bold one):
@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);**
...
Now I get only IDLE state but still there is no ringing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SipAudioCall 类的源代码中有错误。
要解决此问题:
There is an error in the source code of SipAudioCall class.
To work around this issue:
我已经在 sip 演示中实现了相同的场景来接受或拒绝来电。
使用两个按钮 Accept 和 Reject 创建您自己的 Activity (IncomingGui.java)。
在 BroadcastReciever 类中,在来电事件上调用您的 Activity(IncomingGui.java)。
然后在 BroadcastReciever 类中定义以下方法
然后在 IncomingGui.java 中在“接受”和“拒绝”按钮后面定义以下方法。
现在,在来电时,您将有自己的来电活动来接听或拒绝呼叫。
I have implemented same scenario to accept or reject incoming call in sip demo.
Create your own Activity (IncomingGui.java) with two buttons Accept and Reject.
In BroadcastReciever class call your Activity(IncomingGui.java) on incoming call event.
Then define following methods in BroadcastReciever class
Then in IncomingGui.java define following methods behind "Accept" and "Reject" Buttons.
Now on incoming call you will have your own incoming call activity to accept or reject call.