Create a broadcast event receiver and register this file in the manifest file, filtering the intent toAndroid.intent.action.PHONE_STATE
In the IntelliJ because did not prompt thought that does not have this, actually has, increases the permissionAndroid.permission.READ_PHONE_STATE
<receiver android:name=".receiver.CallReceiver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE"/>
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
In receiver, it is determined that the action of intent is the change of the phone state and the status of the parameter change is ringring, that is, when the phone rings, get the mobile phone number
public class CallReceiver extends BroadcastReceiver {
@Override
/span>public void OnReceive ( context Context Span class= "pun", intent Intent ) {
if telephonymanager action_phone_state_changed equals ( intent getaction && "ringing" equals ( intent getstringextra telephonymanager extra_state {
String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
}
}
}
The number that is obtained at this point is the caller ID.
From for notes (Wiz)
Android Development Summary to get the call number