Application launcher icon is not deleted from Home screen when uninstalling android app

前端 未结 2 863
南旧
南旧 2021-02-09 07:56

I\'m using a similar codesnippet as shown below to add an application shortcut on the homescreen:

    Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
            


        
相关标签:
2条回答
  • 2021-02-09 08:33

    I think you can try putting this action in the second Intent: "com.android.launcher.action.INSTALL_SHORTCUT"

    This works for me, the launcher icon gets installed on the home screen, and when I uninstall the application, the icon is removed. Have been struggling some time with this.

    Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
    shortcutIntent.setClassName(this, this.getClass().getName());
    
    Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
    Parcelable iconResource = Intent.ShortcutIconResource.fromContext(
                this,  R.drawable.launcher_icon);
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
    sendBroadcast(intent);
    

    Hope this helps.

    0 讨论(0)
  • 2021-02-09 08:52

    I had the same problem as well.

    Finally, i've figured out that when creating application's shortcut, application's intent must contain the Intent.ACTION_MAIN action, otherwise the shortcut won't be removed from the home screen upon uninstalling the application (not the intent being used for installing the shortcut, which has the com.android.launcher.action.INSTALL_SHORTCUT action) .

    Hope it helps.

    0 讨论(0)
提交回复
热议问题