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

前端之家收集整理的这篇文章主要介绍了java – 如何以编程方式将快捷方式写入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);

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

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

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

谢谢!

解决方法

您无法确定快捷方式的位置.
原文链接:https://www.f2er.com/android/239932.html

猜你在找的Android相关文章