代码之家  ›  专栏  ›  技术社区  ›  Lucas S.

在Android中使用“卸载快捷方式”意图

  •  2
  • Lucas S.  · 技术社区  · 17 年前

    我试图使用以下意图操作,但我得到一个 ActivityNotFoundException 在第一种情况下( startActivity )第二个案子什么都没有( sendBroadcast

    "com.android.launcher.action.UNINSTALL_SHORTCUT"
    

    我尝试将其与以下代码一起使用:

    Intent i = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
    startActivity(i);
    

    Intent i = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
    sendBroadcast(i); 
    
    1 回复  |  直到 13 年前
        1
  •  1
  •   David Hoelzer    11 年前

    首先,您需要拥有适当的权限:

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

    然后你需要做这样的事情:

    Intent intent = new Intent(this, your main activitiy);
    intent.setAction(Intent.ACTION_MAIN);
    Intent removeIntent = new Intent();
    removeIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
    removeIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "HelloWorldShortcut");
    removeIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
    sendBroadcast(removeIntent);