如何以编程写入特定页面的快捷方式在Android发射的主屏幕?快捷方式、屏幕、页面、Android

2023-09-06 13:13:29 作者:丈母娘快把你的女儿交出来

我目前工作的Andr​​oid应用程序,于是我编程写入主屏幕的快捷方式。事情是这样的:

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).

不管怎样,当我在模拟器中运行应用程序,快捷方式是从左边写到第五页(在2.3主屏幕)。随后的运行中写入快捷方式到第4页,从左侧的主屏幕上。

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.

我的问题是:有没有办法写的快捷方式到中心网页或第一页(如通过索引的2-D阵列,似乎保持应用程序的快捷方式)?我失去了一些东西在API中?

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?

谢谢!

推荐答案

您不能决定在哪里的快捷方式会去的。

You cannot decide where the shortcut will go.