xus*_*uso 11 android android-permissions android-shortcut
我想我已经尝试了我在互联网上找到的所有解决方案,但没有人工作 - 没有力量关闭,但桌面上没有任何内容.
现在,我有这个:
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();
}
Run Code Online (Sandbox Code Playgroud)
的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;
}
Run Code Online (Sandbox Code Playgroud)
并在AndroidManifest.xml文件中:
<permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
Run Code Online (Sandbox Code Playgroud)
我错过了什么?谢谢.
xus*_*uso 15
解决了.只需更改清单:
这个:
<permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
Run Code Online (Sandbox Code Playgroud)
对此:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
Run Code Online (Sandbox Code Playgroud)
只是'使用'¬¬
| 归档时间: |
|
| 查看次数: |
8593 次 |
| 最近记录: |