Android - 添加主屏幕快捷方式

标签 android android-launcher

当我在 Android 设备上使用 firebox 浏览器时,我发现他们有一个选项可以为页面添加书签,以便它在 Android 启动器中显示为快捷方式(如应用程序)。

例如:

这是在我打开 Firefox 之前:

enter image description here

在 Firefox 中,我导航到一个页面,然后选择底部的选项:

enter image description here

当我返回启动器时,我可以看到一个新图标。单击该图标可以让我直接在 Firefox 中转到该页面。

enter image description here

有人知道这是如何在应用程序中实现的吗?

最佳答案

这可以通过以下方式完成:

Intent shortcutIntent = new Intent();
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutTitle);
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, shortcutIcon);
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, targetIntent);
shortcutIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");

MyActivity.this.sendBroadcast(shortcutIntent);

在 list 中设置以下权限:

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

如果您打开特定的 URL,您的目标 Intent 将包含您希望启动的 Activity 的 Intent ,并且还可能包含一些包含所需 URL 的额外内容。

关于Android - 添加主屏幕快捷方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32058943/

相关文章:

android - jQuery Mobile 固定页脚在键盘出现时移动

android - 离开页面时如何停止在 initState 中启动的 Timer.periodic

android - 从设备上的 eclipse 启动 android 应用程序非常慢

android - 是否可以有多个启动器 Activity?

android - 像在应用程序启动器中一样实现快捷文本格式

android - 在主屏幕上显示完整的应用程序名称

android - MediaPlayer 在大约 5 秒后停止播放

android - 列出两个内核之间的区别

c# - 目标 sdk 更改后 Xamarin.Android 构建错误

android - 图标大小android,最常见的填充/大小facebook/youtube