簡體   English   中英

Android:從主屏幕刪除應用程序快捷方式

[英]Android: Remove app shortcut from home screen

我正在嘗試從主屏幕刪除應用程序快捷方式。 使用這兩個動作:

  1. com.android.launcher.action.INSTALL_SHORTCUT
  2. com.android.launcher.action.UNINSTALL_SHORTCUT

它對我來說非常完美,但是當我將圖標從應用列表中拖到主屏幕時, UNINSTALL_SHORTCUT不起作用。 那么,這兩種方法之間的區別以及系統在每種情況下的行為方式有什么不同?

private void deleteShortCut(Context context) {

    Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
    shortcutIntent.setClassName("com.example.androidapp", "SampleIntent");
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    shortcutIntent.putExtra("someParameter", "HelloWorld");

    Intent removeIntent = new Intent();
    removeIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    removeIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "ShortcutName");
    removeIntent.putExtra("duplicate", false);

    removeIntent
            .setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");       
    context.sendBroadcast(removeIntent);
}

嘗試這個。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM