gpt4 book ai didi

Android - 将快捷方式添加到主屏幕

转载 作者:搜寻专家 更新时间:2023-11-01 08:41:37 25 4
gpt4 key购买 nike

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

例如:

这是我打开 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com