Android: How to Remove/Uninstall application shortcuts from Home Screen?

后端 未结 3 1306
长发绾君心
长发绾君心 2020-12-09 14:26

I have been trying to (ADD and then) REMOVE my APP\'s shortcut from HOME-SCREEN. ADDING a shortcut works perfectly however I\'m not able to remove the shortcut I\'ve created

3条回答
  •  無奈伤痛
    2020-12-09 14:42

    Here you go:

    private void deleteShortCut(Context context) {
    
        Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
        shortcutIntent.setClassName("com.example.androidapp", "SampleIntent");
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        shortcutIntent.putExtra("someParameter", "HelloWorld");
    
        Intent removeIntent = new Intent();
        removeIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        removeIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "ShortcutName");
        removeIntent.putExtra("duplicate", false);
    
        removeIntent
                .setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");       
        context.sendBroadcast(removeIntent);
    }
    

提交回复
热议问题