No se puede obtener cadena no vacía de PhoneStateListener :: onCallStateChanged
-
08-10-2019 - |
Pregunta
Fuente:
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 )
Hola, España
Estoy utilizando este código, con permiso android.permission.READ_PHONE_STATE
, para obtener tostadas mensaje incluyendo el número de llamada iniciado. Mi problema es que incomingNumber está vacío, doest no importa si la llamada es saliente o incomming, tostadas aparece, pero vacío.
He visto algunas soluciones para esto, pero la solución era conseguir el número con forma completamente diferente y yo quiero saber si mi código se puede utilizar para mis necesidades.
Gracias por los consejos, España
Adam
Solución
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.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow