当前位置: 代码迷 >> Android >> 桌面图标链接
  详细解决方案

桌面图标链接

热度:82   发布时间:2023-08-04 11:23:25.0

我想知道在安装后是否可以选择在用户桌面上设置我的应用程序的自动图标链接?

我知道这样做的唯一方法是用户可以从应用程序列表中手动将其拖动到桌面。 有没有办法自动为用户做这件事(没有他的触摸)?

谢谢,

Moshic。

请不要自动执行! 让用户选择是否需要你的快捷方式!

这是您需要的代码:

        //Create shortcutIntent here with the intent that will launch you app.
        Intent shortcutIntent = (...)
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        final Intent intent = new Intent();
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        // Sets the custom shortcut's title
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,sName);
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);

        // add the shortcut
        intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        sendBroadcast(intent);

不要忘记清单中的额外许可!

        <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
  相关解决方案