In Android projects, it is sometimes necessary to monitor whether the app is installed or uninstalled to make the appropriate action. The whole process was pretty simple.
1. Write a class inheritance Broadcastreceiver
public class Bootreceiver extends broadcastreceiver{@Override public void onreceive (context context, Intent Intent) {< Span style= "font-family: Microsoft Jacob Black;" > //install broadcast monitoring </span> if (Intent.getaction () equals ("Android.intent.action.PACKAGE_ADDED")) { String PackageName = Intent.getdatastring (); SYSTEM.OUT.PRINTLN ("Installed:" +packagename + "package name program"); } Receive the Unload broadcast if (Intent.getaction (). Equals ("Android.intent.action.PACKAGE_REMOVED")) { String PackageName = Intent.getdatastring (); <pre name= "code" class= "java" > System.out.println ("uninstalled:" + packagename + "package name program");} }}
2. Add Permissions
<uses-permission android:name= "Android.permission.INTERNET"/> <uses-permission android:name= " Android.permission.RESTART_PACKAGES "/><uses-permission android:name=" android.permission.RECEIVE_BOOT_ Completed "/>
3. Register receive, under the application node
<receiver android:name= ". Bootreceiver " android:label=" @string/app_name "> <intent-filter> <action android:name=" Android.intent.action.PACKAGE_ADDED "/> <action android:name=" Android.intent.action.PACKAGE_REMOVED "/ > <data android:scheme= "package"/> </intent-filter> </receiver>
The entire feature is now complete.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Andorid How to monitor whether the app is installed or uninstalled