【问题标题】:Android: Remove app shortcut from home screenAndroid:从主屏幕删除应用快捷方式
【发布时间】:2013-09-23 10:49:18
【问题描述】:

我正在尝试从主屏幕中删除应用快捷方式。使用这两个动作:

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

它非常适合我,但是当我将图标从应用程序列表拖到主屏幕时,UNINSTALL_SHORTCUT 不起作用。那么,这两种方法有什么区别吗?系统在每种情况下的表现如何?

【问题讨论】:

    标签: android


    【解决方案1】:
    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);
    }
    

    试试这个。

    【讨论】:

    • 对不起,但对我不起作用。当您发送广播以创建快捷方式时,Imho InstallShortcutReceiver 会在 LauncherModel 中存储一些额外的数据,而当您只是从列表中拖动图标而不发送广播时,系统会执行其他操作。有什么建议吗?
    • codinggeekorg.wordpress.com/tag/home-screen-shortcuts/#– 检查这个链接也许你会得到一些帮助。
    • 您从这些链接中获得了一些帮助?
    • @vshpyrka techsupportalert.com/content/best-android-tips-and-tricks.htm 你必须检查这个链接一次。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-22
    • 1970-01-01
    • 2017-03-16
    • 2010-10-10
    • 2011-09-14
    • 1970-01-01
    相关资源
    最近更新 更多