【发布时间】:2015-07-23 05:56:16
【问题描述】:
我一直在尝试(添加然后)从主屏幕中删除我的应用程序的快捷方式。 添加快捷方式效果很好,但是我无法删除使用以下代码创建的快捷方式。
public void setupShortCut(boolean create) {
shortcutIntent = new Intent();
shortcutIntent.setClassName("com.abc.xyz", "XYZActivity");
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
Intent intentShortcut = new Intent();
intentShortcut.putExtra("android.intent.extra.shortcut.INTENT", shortcutIntent);
intentShortcut.putExtra("android.intent.extra.shortcut.NAME", getResources().getString(R.string.app_name));
intentShortcut.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", icon);
if(create) {
intentShortcut.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
} else {
intentShortcut.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
}
sendBroadcast(intentShortcut);
}
请建议我哪里出错了?
编辑 1:
我的 Manifest 文件已获得所需权限:
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" /
【问题讨论】:
-
您在清单中有
"com.android.launcher.permission.UNINSTALL_SHORTCUT"权限吗? -
是的,我的清单中确实有这个权限。
-
您是否绝对确定当您尝试删除您正在调用
setupShortCut(false)的快捷方式时? -
我对此非常肯定。我已经调试了代码,可以看到控件进入
else。
标签: android