How to remove application shortcut from home screen on uninstall automatically?

后端 未结 3 451
一向
一向 2021-01-13 00:18

I\'m developing an application that should add its shortcut to home screen after installation and remove it after the application is being uninstalled. The application will

3条回答
  •  误落风尘
    2021-01-13 00:46

    Seems that you don't use install_shortcut intent in right way. Probably you create an intent without any parameters. You should to create intent with an action Intent.ACTION_MAIN param.

    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);
    

提交回复
热议问题