[Android] Android monitor APK install replacement unloading broadcast

[Android]Android monitor APK install replacement unloading broadcast

The first is to get the application installation state, through the form of broadcast

The following is and applications related to Broadcast Action

A new ACTION_PACKAGE_ADDED application package is installed on the device, the data include the package name (package newly installed cannot receive the broadcast)

Application of ACTION_PACKAGE_REPLACED a new version of the installed equipment, replace the existing version before

ACTION_PACKAGE_CHANGED an existing application package has been changed, including the package name

ACTION_PACKAGE_REMOVED an existing application package has been removed from the equipment, including the package name (package is being installed cannot receive the broadcast)

The ACTION_PACKAGE_RESTARTED user to restart a package, all processes packets will be killed, all associated with the running time should be removed, including the package name (start package cannot receive the broadcast)

ACTION_PACKAGE_DATA_CLEARED users already know a packet of data, including the package name (clear package cannot receive the broadcast)

Code to achieve 

Define broadcast in AndroidManifest.xml

<receiver android:name=".AppInstallReceiver"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_ADDED" /> 
                <action android:name="android.intent.action.PACKAGE_REPLACED" />
                <action android:name="android.intent.action.PACKAGE_REMOVED" />
                <data android:scheme="package" />
            </intent-filter>
        </receiver>

Here is a selection of

A new ACTION_PACKAGE_ADDED application package is installed on the device, the data include the package name (package newly installed cannot receive the broadcast)

Application of ACTION_PACKAGE_REPLACED a new version of the installed equipment, replace the existing version before

ACTION_PACKAGE_REMOVED an existing application package has been removed from the equipment, including the package name (package is being installed cannot receive the broadcast)

Look at the AppInstallReceiver 

public class AppInstallReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        PackageManager manager = context.getPackageManager();
        if (intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED)) {
            String packageName = intent.getData().getSchemeSpecificPart();
            Toast.makeText(context, "Successfully installed"+packageName, Toast.LENGTH_LONG).show();
        }
        if (intent.getAction().equals(Intent.ACTION_PACKAGE_REMOVED)) {
            String packageName = intent.getData().getSchemeSpecificPart();
            Toast.makeText(context, "Uninstall success"+packageName, Toast.LENGTH_LONG).show();
        }
        if (intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED)) {
            String packageName = intent.getData().getSchemeSpecificPart();
            Toast.makeText(context, "The replacement success"+packageName, Toast.LENGTH_LONG).show();
        }
        

    }

}

The code is relatively simple, according to the received Action to judge whether the application is installed uninstall or replaced by other versions


//////////////////////////////////////////////

The original statement, reproduced please specify

This paper from the   the Ray-Ray blog

This paper addresses 

Thank you for your recommendation and collection

Your support of our power!!

Posted by Terence at November 16, 2013 - 5:34 PM