Android Broadcastreceiver is often used in Android development applications, so take time to tidy up, the province's follow-up in the use of the time to go to Baidu.
Broadcastreceiver several common monitoring
1.BroadcastReceiver Listening dialing
<intent-filter android:priority= "1000" >
<action android:name= "Android.intent.action.NEW_OUTGOING_" Call "/>
</intent-filter>
@Override public
void onreceive (context, Intent Intent) {
//Get dialing number
String call=getresultdata () ;
Add 110 to the phone number before returning the data
setresultdata ("+call");
2.BroadcastReceiver Listening SMS
<receiver android:name= "Smsreceiver" >
<intent-filter android:priority= "1000" >
<action Android:name= "Android.provider.Telephony.SMS_RECEIVED" ></action>
</intent-filter>
</ Receiver>
3.BroadcastReceiver Monitor SD card status
<receiver android:name= ". Sdstatusreceiver ">
<intent-filter >
<action android:name=" android.intent.action.MEDIA_ Mounted "/>
<action android:name=" Android.intent.action.MEDIA_REMOVED "/> <action
android: Name= "Android.intent.action.MEDIA_UNMOUNTED"/>
<data android:scheme= "file"/>
</ Intent-filter>
</receiver
The public class Sdstatusreceiver extends Broadcastreceiver {
@Override
the public void onreceive Intent Intent) {
//Judge what is received in the end broadcast
String action = intent.getaction ();
if ("Android.intent.action.MEDIA_MOUNTED". Equals (Action)) {
Toast.maketext (context, "SD card is available", 0). Show ()
;
else if ("Android.intent.action.MEDIA_REMOVED". Equals (Action)) {
Toast.maketext (context, "SD card Unplugged", 0). Show ();
else if ("Android.intent.action.MEDIA_UNMOUNTED". Equals (Action)) {
Toast.maketext (context, "SD card not available", 0). Show ();}}
4.BroadcastReceiver Monitor Boot
<receiver android:name= "Bootcompeletedreceiver" >
<intent-filter >
<action android:name= " Android.intent.action.BOOT_COMPLETED "/>
</intent-filter>
</receiver>
5.BroadcastReceiver Monitoring application Ann loading and unloading
<receiver android:name= "Intallreceiver" >
<intent-filter >
<action android:name= " Android.intent.action.PACKAGE_REMOVED "/>
<action android:name=" Android.intent.action.PACKAGE_ADDED " >
<data android:scheme= "package" ></data>
</intent-filter>
</receiver>
public class Intallreceiver extends Broadcastreceiver {<br>
@Override public
void OnReceive (context Context, Intent Intent) {
String PackageName = Intent.getdata (). toString ();
String action = Intent.getaction ();
If it is uninstall if
("Android.intent.action.PACKAGE_REMOVED". Equals (Action)) {
Toast.maketext (context, PackageName + "Application uninstalled", 1). Show ();
System.out.println (packagename+ "deleted");
} else if ("Android.intent.action.PACKAGE_ADDED". Equals (Action)) {
Toast.maketext (context, packagename+ "Application Installation" , 1). Show ();
System.out.println (PackageName + "Installed");}
}
Thank you for reading, I hope to help you, thank you for your support for this site!