桌面图标链接

Mos*_*hik 5 android

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

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

谢谢,

Moshic.

Waz*_*_Be 4

请不要自动这样做!让用户选择是否需要您的快捷方式!

这是您需要的代码:

        //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);
Run Code Online (Sandbox Code Playgroud)

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

        <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
Run Code Online (Sandbox Code Playgroud)