小编sub*_*ond的帖子

如何以编程方式将快捷方式写入Android启动器主屏幕上的特定页面?

我目前正在开发一个Android应用程序,然后我以编程方式编写主屏幕的快捷方式.像这样的东西:

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);
Run Code Online (Sandbox Code Playgroud)

(它实际上是一个StackOverflow帖子,指向我这个解决方案).

无论如何,当我在模拟器中运行应用程序时,快捷方式将从左侧(在2.3主屏幕上)写入第五页.后续运行将快捷方式写入主屏幕左侧的第4页.

我的问题是:有没有办法将快捷方式写入中心页面或第一页(比如传递似乎拥有应用程序快捷方式的二维数组的索引)?我错过了API中的内容吗?

谢谢!

java android shortcut launcher homescreen

6
推荐指数
1
解决办法
2972
查看次数

标签 统计

android ×1

homescreen ×1

java ×1

launcher ×1

shortcut ×1