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

前端 未结 2 862
南旧
南旧 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.

提交回复
热议问题