[Android Q&A, Help & Troubleshooting] ultraman94568:
[Q] "UNINSTALL_SHORTCUT" does not work any more for android 4.0 (API 14 and above)

Hi,

The following code "UNINSTALL_SHORTCUT" works for

Android 2.3.3 (API 10) to Android 3.3 (API 13), but does not work any

more with Android 4.0 (API 14) or above.

The Toast message says it is removed, but actually it still exist and

the new one just place on top of the existing one. This creates

multiple shortcuts on top of each other.

Does anyone see the same issue I am seeing or there's other fix for

this with Android 4.0?

Thanks in advance for your help.

=================================

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, "Shortcut

Name");

removeIntent.putExtra("duplicate", false);

removeIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");

context.sendBroadcast(removeIntent);

}

private void addShortCut(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 addIntent = new Intent();

addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);

addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Shortcut Name");

addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,

Intent.ShortcutIconResource.fromContext(context, R.drawable.icon));

addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");

context.sendBroadcast(addIntent);

}

=======================================

AndroidManifest.xml...

<?xml version="1.0" encoding="utf-8"?>

<manifest

package="com.example.addDeleteShortcut"

android:versionCode="8" android:versionName="1.0.0.1">

<uses-permission

android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

<uses-permission

android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />

<supports-screens

android:largeScreens="true"

android:anyDensity="true"

android:smallScreens="true"

android:resizeable="true"

android:normalScreens="true"

/>

<application

android:icon="@drawable/icon"

android:label="@string/app_name"

<activity

android:name=".UIShortcuts"

android:label="@string/app_name" >

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category

android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

<activity

android:name=".shortcutActivity"

android:taskAffinity="com.example.Change"

android:theme="@style/NoBackground"

android:excludeFromRecents="true" >

<intent-filter>

<action android:name="com.example.TOGGLE_SHORTCUT" /

>

<category

android:name="android.intent.category.DEFAULT" />

</intent-filter>

</activity>

</application>

</manifest>