Re: [android-developers] Programmatically delete a home-screen shortcut
Romain, I believe I'm doing something simple wrong, the code below can install shortcut, but removal silently fails (no exceptions or errors in logs except that I see a single line mentioning that ActivityManager processed the call). Tested on Android 2.3.4 phone and on Android 4 tablet with same result.
Can you see anything wrong?
TIA.
private void setupShortcut(boolean remove)
{
Intent shortcutIntent = new Intent(getBaseContext(), RuntimeActivity.class);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_TASK_ON_HOME);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, _preferences.getString(PREF_APP_NAME, "My Shortcut"));
if (remove)
{
addIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
}
else
{
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
addIntent.putExtra("duplicate", false);
File iconFile = new File(getFilesDir(), "icon.png");
if (iconFile.exists())
{
Bitmap icon = BitmapFactory.decodeFile(iconFile.getPath());
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
}
else
{
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher));
}
}
sendBroadcast(addIntent);
}
On Friday, April 10, 2009 12:20:36 PM UTC-4, Romain Guy wrote:
> 1) Is there a way to programmatically delete a home-screen shortcut
> on Android? I know that it can be done manually but I want to do it in
> code.You can use the UNINSTALL_SHORTCUT intent provided by Home.
> 2) Is there a directory where all the contents of the home-screen
> are stored and, if there is, is there a way to update the contents of
> this directory?No, there's no such directory. Home uses a private database that only
Home can access and manipulate.--
Romain Guy
Android framework engineer
romainguy@android.comNote: please don't send private questions to me, as I don't have time
to provide private support. All such questions should be posted on
public forums, where I and others can see and answer them
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home