on device 4.4 and emulator 6.0, the code works, on 5.1 I get null instead of the phone number in the line phoneNumber = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER); when the incoming call ends
public void onReceive(Context context, Intent intent) { if (intent.getAction().equalsIgnoreCase(INCOME_CALL_RECEIVE_ACTION)) { String phone_state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); phoneNumber = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER); if (phone_state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING)) { Intent intentT = new Intent(context, MyService.class); intentT.putExtra("phone", phoneNumber); intentT.putExtra(CONST_STATUS_CODE, CODE_INCOME_START); context.startService(intentT); } if (phone_state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_IDLE)) { Intent intentT = new Intent(context, MyService.class); intentT.putExtra("phone", phoneNumber); intentT.putExtra(CONST_STATUS_CODE, CODE_INCOME_STOP); context.startService(intentT); } } } in the manifest <uses-permission android:name="android.permission.READ_PHONE_STATE" /> and
<intent-filter> <action android:name="android.intent.action.PHONE_STATE" /> </intent-filter>- x555xx