简体   繁体   中英

Possible to track uninstall of android app at user level?

I uninstalled an android mobile app and immediately got SMS that says "sorry to see you go". How did they track that I uninstalled the app?

We can implement a BroadcastReceiver in our application for listening the action "android.intent.action.QUERY_PACKAGE_RESTART" and match our package name inside onReceive() method. If the broadcast was received for selection of our desired application package, then we'll initiate a background thread that will keep monitoring the foreground running activities using the ActivityManager.

Once we find the foreground activity to be "com.android.packageinstaller.UninstallerActivity" , it'll be confirm that user wants to uninstall our application. At this point we'll perform the desired tasks (either display a dialogue, or start another activity overlapping the uninstallation window, etc..) that are to be performed before uninstallation. After performing our task, we'll allow the user to continue with confirming the uninstallation process.

When the user clicks on the Uninstall button under Manage Apps settings, we'll perform our pre-uninstallation tasks and then promt the user to the Confirmation window where user can either confirm to uninstall or can Cancel the operation.

Edit you used to be able to do it this way, the permission required is now deprecated

When uninstalling an app, it fires a Broadcast for "QUERY_PACKAGE_RESTART".

So you would need to have Permissions and to build a Broadcast Receiver

<uses-permission android:name="android.permission.GET_TASKS"/>

And then the manifest.xml

<receiver android:name=".UninstallBroadcastReceiver">
      <intent-filter android:priority="0">
            <action android:name="android.intent.action.QUERY_PACKAGE_RESTART" />
            <data android:scheme="package" />
      </intent-filter>
 </receiver>

UninstallBroadcastReceiver

public class UninstallBroadcastReceiver extends BroadcastReceiver{

    @Override
    public void onReceive(Context context, Intent intent) {
        String[] packageNames = intent.getStringArrayExtra("android.intent.extra.PACKAGES"); 

        if(packageNames!=null){
            for(String packageName: packageNames){
                if(packageName!=null && packageName.equals("YOUR_APPLICATION_PACKAGE_NAME")){
                 //Do Something ?

                }
            }
        }
    }

}

Still not sure how you would need to track if the user cancels the action, but fire a.network call informing your app is about to be uninstalled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM