开发者

How do I programmatically write a shortcut to a specific page on the homescreen of the Android launcher?

开发者 https://www.devze.com 2023-02-18 16:12 出处:网络
I am currently working on an Android application whereupon I programmatically write a shortcut to the home screen.Something like this:

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 shortc开发者_如何学Pythonut 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!


You cannot decide where the shortcut will go.

0

精彩评论

暂无评论...
验证码 换一张
取 消