开发者

Unable to get non-empty string from PhoneStateListener::onCallStateChanged

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜