Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 打状态电话_Android_Telephonymanager - Fatal编程技术网

Android 打状态电话

Android 打状态电话,android,telephonymanager,Android,Telephonymanager,我有下面的代码,并且我已经读到,当双方之间的电话已连接且对方可以看到您正在呼叫并接听您的呼叫时,传出呼叫的振铃状态处于活动状态。空闲状态是指电话断开,摘机状态是指您按下拨号按钮的时刻。我处于摘机和空闲状态,但无法进入振铃状态。可能是什么问题。任何帮助都将不胜感激 public void onReceive(final Context context, Intent intent) { TelephonyManager Tm=(TelephonyManager)contex

我有下面的代码,并且我已经读到,当双方之间的电话已连接且对方可以看到您正在呼叫并接听您的呼叫时,传出呼叫的振铃状态处于活动状态。空闲状态是指电话断开,摘机状态是指您按下拨号按钮的时刻。我处于摘机和空闲状态,但无法进入振铃状态。可能是什么问题。任何帮助都将不胜感激

public void onReceive(final Context context, Intent intent) {
            TelephonyManager Tm=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
            Tm.listen(new PhoneStateListener(){
                public void  onCallStateChanged(int state,String number) {
                    super.onCallStateChanged(state, number);
                    switch (state) {
                      case TelephonyManager.CALL_STATE_IDLE:
                          //when Idle i.e no call
                          Toast.makeText(context, "Phone state Idle", 1).show();

                          break;
                      case TelephonyManager.CALL_STATE_OFFHOOK:

                          //when Off hook i.e in call
                          //Make intent and start your service here
                          Toast.makeText(context, "Phone state Off hook", 1).show();

                          break;
                      case TelephonyManager.CALL_STATE_RINGING:
                          Toast.makeText(context, "Phone state Ringing", 1).show();
                        break;


                      default:
                          break;
                      }
                  }    

            },PhoneStateListener.LISTEN_CALL_STATE);

TelephonyManager.CALL\u STATE\u RINGING
用于接听来电。它不适用于拨出电话时对方的铃声


TelephonyManager.CALL_STATE_RINGING
当您接到来电且手机正在鸣响时会触发


也为您提供信息。没有公共api来检测对方传出呼叫的振铃状态。

可能尝试一下我在线复制的这个助手类,不记得在哪里了

/*Helper class to detect incoming and outgoing calls.*/
public class CallHelper {
    private Activity activity;
    private TelephonyManager tm;
    private CallStateListener callStateListener;
    private OutgoingReceiver outgoingReceiver;
    public String TelephoneNumber;
    public boolean InCall = false;

    public CallHelper(Activity activity) {
        this.activity = activity;
        callStateListener = new CallStateListener();
        outgoingReceiver = new OutgoingReceiver();
    }

    /*Listener to detect incoming calls.*/
    private class CallStateListener extends PhoneStateListener {

        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            switch (state) {
                case TelephonyManager.CALL_STATE_RINGING: {
                    TelephoneNumber = incomingNumber;
                    inout = "in";
                    InCall = false;
                    break;
                }
                case TelephonyManager.CALL_STATE_OFFHOOK: {
                    if (!InCall) {
                        InCall = true;
                        //Do your stuff here when in call...
                    }
                    break;
                }
                case TelephonyManager.CALL_STATE_IDLE: {
                    InCall = false;
                    break;
                }
                default: {
                    InCall = false;
                    break;
                }
            }
        }
    }

    /*Broadcast receiver to detect the outgoing calls.*/
    public class OutgoingReceiver extends BroadcastReceiver {
        public OutgoingReceiver() { }

        @Override
        public void onReceive(Context context, Intent intent) {
            TelephoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        }
    }

    /*Start calls detection.*/
    public void start() {
        tm = (TelephonyManager) activity.getSystemService(Activity.TELEPHONY_SERVICE);
        tm.listen(callStateListener, PhoneStateListener.LISTEN_CALL_STATE);

        IntentFilter intentFilter = new IntentFilter(Intent.ACTION_NEW_OUTGOING_CALL);
        activity.registerReceiver(outgoingReceiver, intentFilter);
    }

    /*Stop calls detection.*/
    public void stop() {
        tm.listen(callStateListener, PhoneStateListener.LISTEN_NONE);
        activity.unregisterReceiver(outgoingReceiver);
    }
}

所以没有办法检测对方何时接听电话?正如我所说的。。没有用于此的公共api。。您可以检查内部API。。