对桌面的任何应用程序创建一个快捷方式 [英] Create a shortcut for any app on desktop
本文介绍了对桌面的任何应用程序创建一个快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想我已经尝试了所有我在互联网上找到了解决方案,但没有一个人 - 没有工作紧密力,但没有出现在桌面 - 。现在,我已经这样的:
I think I've tried all the solutions I found on the internet, but no one worked -no force close, but nothing appears on desktop-. Now, I've this:
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()是这样的:
The app.getIntentShortcut() is this:
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"/>
我在想什么?谢谢你。
What am I missing? Thanks.
推荐答案
解决。只要改变在清单:
Solved. Just change at manifest:
这样的:
<permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
这样:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
只是一个'使用'¬¬
Just an 'uses' ¬¬
这篇关于对桌面的任何应用程序创建一个快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文