Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何为桌面上的任何应用创建快捷方式?_Android_Android Permissions_Android Shortcut - Fatal编程技术网

Android 如何为桌面上的任何应用创建快捷方式?

Android 如何为桌面上的任何应用创建快捷方式?,android,android-permissions,android-shortcut,Android,Android Permissions,Android Shortcut,我想我已经尝试了我在互联网上找到的所有解决方案,但是没有人工作——没有强制关闭,但是桌面上什么也没有出现 现在,我有这个: private void createShortcutOnDesktop(Application app) { Intent shortcutIntent = new Intent(); shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, app.getIntentShortcut()); s

我想我已经尝试了我在互联网上找到的所有解决方案,但是没有人工作——没有强制关闭,但是桌面上什么也没有出现

现在,我有这个:

private void createShortcutOnDesktop(Application app) {

    Intent shortcutIntent = new Intent();
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, app.getIntentShortcut());
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, app.getName());
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.home_button));
    shortcutIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    this.sendBroadcast(shortcutIntent);
    finish();

}
app.getIntentShortcut()

AndroidManifest.xml
文件中:

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


我错过了什么?谢谢。

问题解决了。只需在舱单上更改:

这:


为此:

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


只需一个“使用”、

作为参考,编辑您的问题就足以让它再次登上头版。请提供完整的源代码。您的代码似乎在程序执行时生成了桌面快捷方式!是否有一种方法可以在运行应用程序之前在安装应用程序时创建桌面图标?不,您不能,因为java代码必须位于启动应用程序时运行的主活动中
<permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>