Não é possível obter o TelephonyManager.CALL_STATE_RINGING

Eu adicionei este é o meu file manifesto –

<receiview android:name=".ServiceReceiview"> <intent-filter> <action android:name="android.intent.action.PHONE_STATE" /> </intent-filter> </receiview> </application> <uses-permission android:name="android.permission.READ_PHONE_STATE"> </uses-permission> 

Então, minha class de service é assim –

 public class ServiceReceiview extends BroadcastReceiview { @Oviewride public void onReceive(Context context, Intent intent) { MyPhoneStateListener phoneListener = new MyPhoneStateListener(); TelephonyManager telephony = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); telephony.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE); } public void onReceive (Context context, intenção intenção) { public class ServiceReceiview extends BroadcastReceiview { @Oviewride public void onReceive(Context context, Intent intent) { MyPhoneStateListener phoneListener = new MyPhoneStateListener(); TelephonyManager telephony = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); telephony.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE); } 

}

e meu PhoneStateListener é –

 public class MyPhoneStateListener extends PhoneStateListener { public void onCallStateChanged(int state, String incomingNumber) { Log.i("telephony-example", "State changed: " + stateName(state)); } String stateName(int state) { switch (state) { case TelephonyManager.CALL_STATE_IDLE: Log.d("DEBUG", "***********IDLE********"); return "Idle"; case TelephonyManager.CALL_STATE_OFFHOOK: Log.d("DEBUG", "***********OFFHOOK********"); return "Off hook"; case TelephonyManager.CALL_STATE_RINGING: Log.d("DEBUG", "***********RINGING********"); return "Ringing"; } return Integer.toString(state); } } public class MyPhoneStateListener extends PhoneStateListener { public void onCallStateChanged(int state, String incomingNumber) { Log.i("telephony-example", "State changed: " + stateName(state)); } String stateName(int state) { switch (state) { case TelephonyManager.CALL_STATE_IDLE: Log.d("DEBUG", "***********IDLE********"); return "Idle"; case TelephonyManager.CALL_STATE_OFFHOOK: Log.d("DEBUG", "***********OFFHOOK********"); return "Off hook"; case TelephonyManager.CALL_STATE_RINGING: Log.d("DEBUG", "***********RINGING********"); return "Ringing"; } return Integer.toString(state); } } public class MyPhoneStateListener extends PhoneStateListener { public void onCallStateChanged(int state, String incomingNumber) { Log.i("telephony-example", "State changed: " + stateName(state)); } String stateName(int state) { switch (state) { case TelephonyManager.CALL_STATE_IDLE: Log.d("DEBUG", "***********IDLE********"); return "Idle"; case TelephonyManager.CALL_STATE_OFFHOOK: Log.d("DEBUG", "***********OFFHOOK********"); return "Off hook"; case TelephonyManager.CALL_STATE_RINGING: Log.d("DEBUG", "***********RINGING********"); return "Ringing"; } return Integer.toString(state); } 

}

Posso view o estado IDLE.

Mas quando eu ligo eu não entendo o estado do toque. Por quê?

One Solution collect form web for “Não é possível obter o TelephonyManager.CALL_STATE_RINGING”

Eu acho que você está misturando duas abordagens paira obter o estado do telefone. Se você usair o filter de intenção e o receptor de transmissão, então, no receptor, não será necessário chamair o TelephonyManager (). Basta viewificair a intenção recebida assim:

 public void onReceive(Context context, Intent intent) { String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)) { Log.d("MPR", "Its Ringing [" + number + "]"); } if (TelephonyManager.EXTRA_STATE_IDLE.equals(state)) { Log.d("MPR", "Its Idle"); } if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(state)) { Log.d("MPR", "Its OffHook"); } } public void onReceive (Context context, intenção intenção) { public void onReceive(Context context, Intent intent) { String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)) { Log.d("MPR", "Its Ringing [" + number + "]"); } if (TelephonyManager.EXTRA_STATE_IDLE.equals(state)) { Log.d("MPR", "Its Idle"); } if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(state)) { Log.d("MPR", "Its OffHook"); } } { public void onReceive(Context context, Intent intent) { String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)) { Log.d("MPR", "Its Ringing [" + number + "]"); } if (TelephonyManager.EXTRA_STATE_IDLE.equals(state)) { Log.d("MPR", "Its Idle"); } if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(state)) { Log.d("MPR", "Its OffHook"); } } } public void onReceive(Context context, Intent intent) { String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)) { Log.d("MPR", "Its Ringing [" + number + "]"); } if (TelephonyManager.EXTRA_STATE_IDLE.equals(state)) { Log.d("MPR", "Its Idle"); } if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(state)) { Log.d("MPR", "Its OffHook"); } } { public void onReceive(Context context, Intent intent) { String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)) { Log.d("MPR", "Its Ringing [" + number + "]"); } if (TelephonyManager.EXTRA_STATE_IDLE.equals(state)) { Log.d("MPR", "Its Idle"); } if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(state)) { Log.d("MPR", "Its OffHook"); } } } public void onReceive(Context context, Intent intent) { String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)) { Log.d("MPR", "Its Ringing [" + number + "]"); } if (TelephonyManager.EXTRA_STATE_IDLE.equals(state)) { Log.d("MPR", "Its Idle"); } if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(state)) { Log.d("MPR", "Its OffHook"); } } { public void onReceive(Context context, Intent intent) { String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)) { Log.d("MPR", "Its Ringing [" + number + "]"); } if (TelephonyManager.EXTRA_STATE_IDLE.equals(state)) { Log.d("MPR", "Its Idle"); } if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(state)) { Log.d("MPR", "Its OffHook"); } } } public void onReceive(Context context, Intent intent) { String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)) { Log.d("MPR", "Its Ringing [" + number + "]"); } if (TelephonyManager.EXTRA_STATE_IDLE.equals(state)) { Log.d("MPR", "Its Idle"); } if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(state)) { Log.d("MPR", "Its OffHook"); } } 
Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.