6

I am currently working on an Android application whereupon I programmatically write a shortcut to the home screen. Something like this:

Intent shortcutIntent = new Intent();
shortcutIntent.setClassName(ai.packageName, ai.name);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
shortcutIntent.addCategory(Intent.ACTION_PICK_ACTIVITY);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);

BitmapDrawable bd=(BitmapDrawable)(res.get(app_id).activityInfo.loadIcon(p).getCurrent());
Bitmap newbit;
newbit=bd.getBitmap();
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, newbit);

intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
context.sendBroadcast(intent);

(it was actually a StackOverflow post that pointed me to this solution).

Anyway, when I run the app in the emulator, the shortcut is written to the fifth page from the left(on 2.3 home screen ). A subsequent run writes the shortcut to the 4th page from the left on the home screen.

My question is this: is there a way to write the shortcut to the center page or the first page (like passing indexes for the 2-D array that seems to hold the app shortcuts)? am I missing something in the API?

Thanks!

subsecond
  • 63
  • 1
  • 4

1 Answers1

9

You cannot decide where the shortcut will go.

Romain Guy
  • 97,993
  • 18
  • 219
  • 200
  • I was afraid that would be the case. Can you elaborate a bit on your answer? – subsecond Mar 18 '11 at 04:56
  • 1
    There's nothing to elaborate on, Launcher doesn't let you choose where the shortcut will go. There is no API to achieve this. – Romain Guy Mar 18 '11 at 17:08
  • 1
    Okay. It seems odd though to allow a shortcut to be created this way and not be able to have finer control as to where it will be written. I don't the see the utility in it. Thanks for your answer, though. I will have to try a different approach. – subsecond Mar 18 '11 at 19:02