2013-09-23 38 views
0

我试图从主屏幕删除应用快捷方式。使用此两个动作:Android:从主屏幕删除应用快捷方式

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

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

回答

0
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); 
} 

试试这个。

+0

对不起,但不适合我。 Imho InstallShortcutReceiver在发送广播以创建快捷方式时将一些额外的数据存储在LauncherModel中,而当您只是从列表中拖动图标而不发送广播系统时,会执行其他操作。有什么建议么? –

+0

codinggeekorg.wordpress.com/tag/home-screen-shortcuts/#-检查此链接也许你会得到一些帮助。 –

+0

http://android.stackexchange.com/questions/37327/how-can-i-remove-unwanted-app-icons-from-the-screen这一个也。 –

相关问题