android – 为桌面上的任何应用程序创建快捷方式

我想我已经尝试过在互联网上发现的所有解决方案,但没有人工作 – 没有强制关闭,但桌面上没有任何内容.现在,我有这个:
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()是这样的:

public Intent getIntentShortcut()
{       

    Intent i = new Intent();
    i.setClassName(packageName,name);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    return i;
}

在清单中:

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

我失踪了什么谢谢.

解决方法

解决了.只是在清单上改变:

这个:

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

到这个:

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

只是一个’使用’¬¬

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...