2

I know how to add or remove my android application shortcut to home screen programmatically? But I do not know how to remove the shortcut on application uninstallation time.

You know when you create a shortcut programmatically, after user uninstalls the application your shortcut remains in the home screen and does not open any application.

How can I know if my app is uninstalling and remove the shortcut on that time?

Or I want to know if there is a way that the application calls my shortcut remove method when it is uninstallig?

thanks,

Cœur
  • 37,241
  • 25
  • 195
  • 267
Bob
  • 22,810
  • 38
  • 143
  • 225
  • Possible duplicate of [How to remove application shortcut from home screen on uninstall automatically?](http://stackoverflow.com/questions/2131690/how-to-remove-application-shortcut-from-home-screen-on-uninstall-automatically) – Cœur Mar 19 '17 at 01:49

3 Answers3

1

Launcher application takes care of creating/deleting application shortcuts, not Play Store. If you want to remove app shortcut, you can broadcast an intent as below :

PackageManager pm = context.getPackageManager();
        // Intent to Start activity
        ApplicationInfo info = pm.getApplicationInfo(packageName, 0);
        if (info != null) {
            Intent shortcutIntent = pm
                    .getLaunchIntentForPackage(packageName);
            if (shortcutIntent != null) {
                final Intent removeIntent = new Intent();
                removeIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
                        shortcutIntent);
                removeIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
                        info.loadLabel(pm));
                removeIntent.putExtra("duplicate", false);

                removeIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
                context.sendBroadcast(removeIntent);
            }
        }

After sending this broadcast, app shortcut will be removed. Please check whether third party application has permission to remove app shortcuts or not.

Hope this will help you.

Harry
  • 422
  • 3
  • 11
  • I know about removing shortcut method. The time of removing is important for me. I want to remove it at uninstallation time only. – Bob Sep 15 '14 at 11:36
  • The way which I have mentioned is the only apis given for third party applications to remove app shortcut. If you want to remove at the time of app uninstallation, you need to make change in launcher application but again if user uses another launcher application, your change will not make any effect. – Harry Sep 22 '14 at 07:52
  • `EXTRA_SHORTCUT_INTENT` and `EXTRA_SHORTCUT_NAME` are deprecated as of API level 26 (Oreo). Is there a way to do this for API level 26 and up? – Erlend K.H. Jan 28 '19 at 17:26
0

I think play store will handle this one when you uninstall the app all shortcuts going to be deleted you dont need to handle this

Dondaldo
  • 56
  • 5
  • "You know when you create a shortcut programmatically, after user uninstalls the application your shortcut remains in the home screen and does not open any application" – Bob Sep 15 '14 at 06:18
0
BroadcastReceiver mApplicationsReceiver = new ApplicationsIntentReceiver();

First register intent receiver once an app is uninstalled,

IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
filter.addDataScheme("package");
registerReceiver(mApplicationsReceiver, filter);

Then do what you want on BroadcastReceiver,

private class ApplicationsIntentReceiver extends BroadcastReceiver {
    public void onReceive(Context context, Intent intent) {
        // Toast.makeText(context, "APP CHANGED", Toast.LENGTH_LONG).show();
        // remove the shortcut from the home screen
    }
}
TechArcSri
  • 1,982
  • 1
  • 13
  • 20