How do I programmatically write a shortcut to a sp

2019-01-28 00:23发布

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!

1条回答
何必那么认真
2楼-- · 2019-01-28 01:01

You cannot decide where the shortcut will go.

查看更多
登录 后发表回答