How does Dolphin web browser get notified when it&

2019-02-03 02:36发布

问题:

Background

It might be useful for apps to allow to ask the user to answer why it was decided to uninstall them.

The problem

It seems that the Dolphin web browser app (and "everything me launcher") somehow managed to bypass it, and now it shows a webpage (on the default web browser) each time the app is being uninstalled.

This happens even if I uninstall using ADB.

As a user, I really hate it, but it's still interesting since as far as I know, apps can't get intents for the uninstallation of themselves.

Question

How could it be? How did they manage to overcome this?

Is this a hack?

回答1:

Maybe the app has a background service which checks the foreground app when it's own onDestroy() callback is fired, and if the foreground app is the uninstalling activity of android Package installer, it launch a new intent for the webpage?



回答2:

My guess is that they're using ACTION_PACKAGE_REMOVED. http://developer.android.com/reference/android/content/Intent.html#ACTION_PACKAGE_REMOVED Either that, or Robin Hood and Frei Tuck method, where each one listens to broadcasts events from the other.
Just a guess, but will look into it.
This might be an option: How can an app detect that it's going to be uninstalled?



回答3:

Please try to get the top activity in the task via ActivityManager, and check if it is the uninstall activity.

Core code:

ComponentName topActivity = mActivityManager.getRunningTasks(1).get(0).topActivity;
String packageName = topActivity.getPackageName();
String className = topActivity.getClassName();
Log.v(TAG, "packageName" + packageName);
Log.v(TAG, "className" + className);

if ("com.android.packageinstaller".equals(packageName)
    && "com.android.packageinstaller.UninstallerActivity".equals(className)) {
//Do anything you want here
}