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

后端 未结 3 1307
长发绾君心
长发绾君心 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);
    }
    
    0 讨论(0)
  • For remove shortcut try with below code...

    final Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
    shortcutIntent.setComponent(new ComponentName(this.getPackageName(), "YourClassName"));
    
    final Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));          
    intent.setComponent(new ComponentName(this.getPackageName(), "YourClassName"));                     
    intent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
    
    sendBroadcast(intent, null);
    

    add below permission to your Manifest file:

    <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />   
    
    0 讨论(0)
  • 2020-12-09 14:56

    FIGURED OUT THE ROOT CAUSE :-)

    I figured out the reason why it wasn't working for me. I am using a different 3rd party launcher (other than Stock android launcher) on my phone. CREATING and REMOVING an App-Shortcut works as long as the launcher you are using supports that operation. I ran the above code on default launcher and it works like a charm :)

    Thank you everyone for your replies!

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