【问题标题】:Android outgoing Call Ringing StageAndroid 拨出呼叫振铃阶段
【发布时间】:2017-07-06 05:43:49
【问题描述】:

我试图进入拨出电话的振铃阶段。我已经用 NEW_OUTGOING_CALL 和 PHONE_STATE 操作尝试了 BroadcastReceiver。但我没有得到接收器的振铃阶段。我现在明白接收器不会告诉你振铃阶段。我见过同样的查询:- Android - How to detect outgoing call is answered or received? 我也应用了这个解决方案,但我仍然没有得到任何解决方案。我已经用动作 NotificationListenerService 声明了服务,我需要做一些额外的事情或其他事情......

我认为获得拨出电话的振铃阶段或在另一端接听电话这是可能的..

请帮忙!

【问题讨论】:

  • 我看到响应表明无法确定拨出电话另一端的线路是否在振铃。不过我不知道这一点。

标签: android broadcastreceiver phone-call notification-listener


【解决方案1】:

在清单文件中,您应该具有以下权限来检查呼出呼叫:

<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>

以及广播接收器的代码:

public class PhoneStateChecking extends BroadcastReceiver {
    boolean hasCallStateRinging = false;

    @Override
    public void onReceive(Context context, Intent intent) {

        Log.d("Intent", intent.toString());
        if(intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
            Log.e("CAll-STATUS", "out going Call");
        }

        //        Checking for the call status
        try {
            // TELEPHONY MANAGER class object to register one listner
            TelephonyManager tmgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            //Create Listner
            MyPhoneStateListener PhoneListener = new MyPhoneStateListener();
            // Register listener for LISTEN_CALL_STATE
            tmgr.listen(PhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class MyPhoneStateListener extends PhoneStateListener {
        public void onCallStateChanged(int state, String incomingNumber) {
            switch (state) {
                case TelephonyManager.CALL_STATE_RINGING:
                    if (hasCallStateRinging)
                        return;
                    else {
                        hasCallStateRinging = true;
                        Log.e("CAll-STATUS", "CALL_STATE_RINGING");
                    }
                    break;
                case TelephonyManager.CALL_STATE_OFFHOOK:
                    if(!hasCallStateRinging){
                        hasCallStateRinging = true;
                        Log.e("CAll-STATUS", "CALL_STATE_OFFHOOK");
                    }
                    break;
                case TelephonyManager.CALL_STATE_IDLE:
                    if (hasCallStateRinging) {
                        hasCallStateRinging = false;
                        Log.e("CAll-STATUS", "CALL_STATE_IDLE");
                    }
                    break;
            }
        }
    }

}

【讨论】:

  • 感谢您回复此查询,但我已经尝试过,结果相同。
  • 当用户接听电话时,我已经使用通知侦听器获取系统通知“正在进行中”。
猜你喜欢
  • 1970-01-01
  • 2016-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-04
相关资源
最近更新 更多