Under Android, to receive broadcast information, the broadcast receiver will have to be implemented by ourselves, and we can inherit broadcastreceiver and we can have a broadcast receiver. A receiver is not enough, we have to rewrite the broadcastreceiver inside the Onreceiver method, and then register the broadcast
There are two methods, one is code dynamic registration:
Generate broadcast Processing
Smsbroadcastreceiver = new Smsbroadcastreceiver ();
Instantiate the filter and set the broadcast to filter
Intentfilter intentfilter = new Intentfilter ("Android.provider.Telephony.SMS_RECEIVED");
Register for Broadcast
BroadCastReceiverActivity.this.registerReceiver (Smsbroadcastreceiver, Intentfilter);
The second is to configure the broadcast in Androidmanifest.xml
<!--broadcast registered-->
<receiver android:name= ". Smsbroadcastreceiver ">
<intent-filter android:priority=" >
<action android:name= " Android.provider.Telephony.SMS_RECEIVED "/>
</intent-filter>
</receiver>
The difference between the two registration types is:
1 The first is not resident type broadcasts, that is, the broadcast follows the life cycle of the program.
2 The second is a resident type, which means that when an application shuts down, the program is automatically run by the system call if there is information broadcast.