문제

Source:

listener = new PhoneStateListener()
    {
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            super.onCallStateChanged(state, incomingNumber);
            Toast toast = Toast.makeText(getApplicationContext(), incomingNumber, Toast.LENGTH_LONG);
            toast.show();
        }

    };

    ((TelephonyManager)getSystemService(TELEPHONY_SERVICE)).listen(listener , PhoneStateListener.LISTEN_CALL_STATE )

Hi,
I am using this code, with android.permission.READ_PHONE_STATE permission, to get toast message including number of started call. My problem is that incomingNumber is empty, it doest not matter if call is outgoing or incomming, toast appear, but empty.
I have seen some solutions for this, but solution was to get the number with completely different way and I wanna know if my code can be used for my needs.
Thanks for advices,
Adam

도움이 되었습니까?

해결책

please include permission in your application.

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


if(state == TelephonyManager.CALL_STATE_RINGING){
Toast toast = Toast.makeText(getApplicationContext(), incomingNumber, Toast.LENGTH_LONG);
toast.show();
}

CALL_STATE_OFFHOOK return null if its first call. So you should use CALL_STATE_RINGING.

Hopefully it will help you.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top