【问题标题】:How do I programmatically write a shortcut to a specific page on the homescreen of the Android launcher?如何以编程方式编写 Android 启动器主屏幕上特定页面的快捷方式?
【发布时间】:2011-07-17 18:19:29
【问题描述】:

我目前正在开发一个 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 中遗漏了什么吗?

谢谢!

【问题讨论】:

    标签: java android shortcut launcher homescreen


    【解决方案1】:

    您无法决定快捷方式的去向。

    【讨论】:

    • 我担心会是这样。你能详细说明一下你的答案吗?
    • 没有什么可详细说明的,Launcher 不允许您选择快捷方式的去向。没有 API 可以实现这一点。
    • 好的。尽管允许以这种方式创建快捷方式并且无法更好地控制其写入位置,但这似乎很奇怪。我没有看到其中的实用程序。不过谢谢你的回答。我将不得不尝试不同的方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-22
    • 1970-01-01
    • 2012-08-31
    • 2013-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多