来电时无振铃事件

发布于 2025-01-02 15:28:15 字数 2974 浏览 1 评论 0原文

我不知道哪里出了问题。 侦听器不会捕获 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

指尖微凉心微凉 2025-01-09 15:28:15

SipAudioCall 类的源代码中有错误。

要解决此问题:

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

There is an error in the source code of SipAudioCall class.

To work around this issue:

incomingCall = wtActivity.manager.takeAudioCall(intent, null);
incomingCall.setListener(listener, true);
忆依然 2025-01-09 15:28:15

我已经在 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 中在“接受”和“拒绝”按钮后面定义以下方法。
现在,在来电时,您将有自己的来电活动来接听或拒绝呼叫。

    public void onCallAcceptButton(View view){
    IncomingCallReceiver.answerIncomingCall();
}

    public void onCallRejectButton(View view){
    IncomingCallReceiver.rejectIncomingCall();
    this.finish();

}

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.

        WalkieTalkieActivity wtActivity = (WalkieTalkieActivity) context;
        incomingCall = wtActivity.manager.takeAudioCall(intent, listener);
        showIncomingCallGui(intent, context); 
        wtActivity.call = incomingCall;

Then define following methods in BroadcastReciever class

    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());
    }

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.

    public void onCallAcceptButton(View view){
    IncomingCallReceiver.answerIncomingCall();
}

    public void onCallRejectButton(View view){
    IncomingCallReceiver.rejectIncomingCall();
    this.finish();

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文