如何在主屏幕中检测快捷方式

use*_*926 15 android

我有一个应用程序,允许您在主屏幕中创建"快捷方式".但我可以检测到"快捷方式"是否已经存在,我不必再次创建它.谢谢.

sty*_*972 10

我遇到了同样的问题.我不认为它可能会告诉你它是否存在,但我认为我用过的东西也适合你.

只需在添加快捷方式之前卸载快捷方式!

intent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(intent);

intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(intent);
Run Code Online (Sandbox Code Playgroud)

只需确保将以下内容添加到清单文件中即可.

<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"/>    
Run Code Online (Sandbox Code Playgroud)

  • 这不适用于最新的Android版本(> = Marshmallow) (3认同)

Vas*_*asu 8

我不知道是否可以检测到快捷方式,但是不是卸载然后安装,而是可以使用Extra字段作为

intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);
...
intent.putExtra("duplicate", false);
...
sendBroadcast(intent);
Run Code Online (Sandbox Code Playgroud)

  • 忘掉这个方法吧.不再适用于Jellybean 2.它确实适用于旧设备 - 只是测试它 (13认同)
  • @SIrCodealot这个方法仍然有效 - 它只适用于任何Jelly Bean版本 - 只是在Lollipop上测试过 (2认同)