Found several answers here, but not one did not work for me. Where is the mistake?

public class MainActivity extends Activity { final String LOG_TAG = "myLog"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TelephonyManager TelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); TelephonyMgr.listen(new TeleListener(), PhoneStateListener.LISTEN_CALL_STATE); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); return true; } class TeleListener extends PhoneStateListener { public void onCallStateChanged(int state, String incomingNumber) { super.onCallStateChanged(state, incomingNumber); switch (state) { case TelephonyManager.CALL_STATE_IDLE: // CALL_STATE_IDLE; break; case TelephonyManager.CALL_STATE_OFFHOOK: // CALL_STATE_OFFHOOK; break; case TelephonyManager.CALL_STATE_RINGING: // CALL_STATE_RINGING Log.d(LOG_TAG,"CALL_STATE_RINGING " + incomingNumber); break; default: break; } } } } 
  • what exactly does not work? - Vladyslav Matviienko
  • He does not give me the number. Log.d (LOG_TAG, "CALL_STATE_RINGING" + incomingNumber); - Dmitry Polishchuk
  • And what gives? null? or not called? Let us not be ticks from you, and you tell us yourself - Vladyslav Matviienko
  • Permissions added necessary? - Vladyslav Matviienko
  • When you call, writes CALL_STATE_RINGING to the log, and that's it, no number. The permissions are: <uses-android: name = "android.permission.READ_PHONE_STATE" /> <uses-android: name = "android.permission.CALL_PHONE" /> - Dmitry Polishchuk

0