Not able to get the TelephonyManager.CALL_STATE_RINGING

后端 未结 1 1103
野趣味
野趣味 2020-12-03 12:09

I added this is my manifest file -

        
        
            

        
相关标签:
1条回答
  • 2020-12-03 12:25

    I think you are mixing up two approaches to get phone state. If you use the intent-filter and broadcast receiver, then in the receiver no need to call the TelephonyManager's listen(). Just check the received intent like this :

    public void onReceive(Context context, Intent intent) {
        String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
        String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
        if (TelephonyManager.EXTRA_STATE_RINGING.equals(state))
        {
            Log.d("MPR", "Its Ringing [" + number + "]");
        }
        if (TelephonyManager.EXTRA_STATE_IDLE.equals(state))
        {
            Log.d("MPR", "Its Idle");
        }
        if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(state))
        {
            Log.d("MPR", "Its OffHook");
        }
    }
    
    0 讨论(0)
提交回复
热议问题