How to detect incoming calls, in an Android device?

前端 未结 10 1708
一向
一向 2020-11-22 02:27

I\'m trying to make an app like, when a call comes to the phone I want to detect the number. Below is what I tried, but it\'s not detecting incoming calls.

I want t

10条回答
  •  粉色の甜心
    2020-11-22 02:52

    private MyPhoneStateListener phoneStateListener = new MyPhoneStateListener();
    

    to register

    TelephonyManager telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
    

    and to unregister

    TelephonyManager telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);
    

提交回复
热议问题