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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With