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
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);
}
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" />
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!