I have the same problem with you, and I can't remove the shortcut on
Android 2.3 also.
And after I remove the shortcut manually, I can't create that shortcut
again. That is to say, I can only create the shortcut for one time.
here is my codes:
void createShortcut(Context context, String title, Bitmap icon, boolean
isInstall) {
Intent shortcutIntent = new Intent(Intent.ACTION_VIEW);
shortcutIntent.setPackage(context.getPackageName());
Intent i = new Intent();
i.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
i.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
i.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
i.putExtra("duplicate", false);
i.setAction(isInstall ?
"com.android.launcher.action.INSTALL_SHORTCUT" :
"com.android.launcher.action.UNINSTALL_SHORTCUT");
context.sendBroadcast(i);
}
And I have already add the
user-permission com.android.launcher.permission.UNINSTALL_SHORTCUT yet.
Did you figure out your issue?
Or anybody could help us out?
Thank you.
On Saturday, March 31, 2012 5:46:02 AM UTC+8, Ultraman wrote:
>
> Hi,
>
> The following code "INSTALL_SHORTCUT" & "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
> xmlns:android="http://schemas.android.com/apk/res/android"
> 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>
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en