Apps in your phone send broadcasts when they're installed, updated, and uninstalled
Manifest file
<?XML version= "1.0" encoding= "Utf-8"?><Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Xidian.dy.com.chujia"> <uses-permissionAndroid:name= "Android.permission.RECEIVE_SMS"/> <ApplicationAndroid:allowbackup= "true"Android:icon= "@mipmap/ic_launcher"Android:label= "@string/app_name"Android:supportsrtl= "true"Android:theme= "@style/apptheme"> <ActivityAndroid:name=". Mainactivity "Android:label= "Main interface"> <Intent-filter> <ActionAndroid:name= "Android.intent.action.MAIN" /> <categoryAndroid:name= "Android.intent.category.LAUNCHER" /> </Intent-filter> </Activity> <receiverAndroid:name=". Sdstatusreceiver "> <Intent-filter> <ActionAndroid:name= "Android.intent.action.PACKAGE_ADDED"/> <ActionAndroid:name= "Android.intent.action.PACKAGE_CHANGED"/> <ActionAndroid:name= "Android.intent.action.PACKAGE_REMOVED"/> <DataAndroid:scheme= "Package"/> </Intent-filter> </receiver> </Application></Manifest>
Set the broadcast to receive in the manifest file
Broadcast recipient
PackageXidian.dy.com.chujia;ImportAndroid.content.BroadcastReceiver;ImportAndroid.content.Context;Importandroid.content.Intent;ImportAndroid.net.Uri;ImportAndroid.widget.Toast;/*** Created by Dy on 2016/7/12.*/ Public classAppstatusreceiverextendsBroadcastreceiver {@Override Public voidOnReceive (Context context, Intent Intent) {//determine the type of broadcast receivedString action =intent.getaction (); Uri URI=Intent.getdata (); if("Android.intent.action.PACKAGE_ADDED". Equals (action)) {Toast.maketext (context,uri.tostring ()+ "be Installed", Toast.length_long). Show (); } Else if("Android.intent.action.PACKAGE_CHANGED". Equals (action)) {Toast.maketext (context, uri.tostring ()+ "has been updated", Toast.length_short). Show (); } Else if("Android.intent.action.PACKAGE_REMOVED". Equals (action)) {Toast.maketext (context, uri.tostring ()+ "uninstalled", Toast.length_short). Show (); } }}
App Status Monitor broadcast