Andorid How to monitor whether the app is installed or uninstalled

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.