【问题标题】:How to create and remove application shortcut into home screen?如何在主屏幕中创建和删除应用程序快捷方式?
【发布时间】:2012-06-13 12:35:52
【问题描述】:

我正在创建应用程序快捷方式。它工作正常。但我无法删除此快捷方式。如何删除我的应用程序快捷方式。在我的主屏幕中包含很多应用程序快捷方式。如何删除..
如果可能,请发送有关如何删除应用程序快捷方式的信息。否则,如果不可能发送原因。请回复您的答案,cmets 对我很有价值。谢谢。
我的示例代码在这里...

    Button btnShortcut = (Button) findViewById(R.id.btnCreateShortcut);
    btnShortcut.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View arg0) 
        {
            Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
            shortcutintent.putExtra("duplicate", false);
            shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
            Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher);
            shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
            shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext() , MyActivity.class));
            sendBroadcast(shortcutintent);
        }
    });

我的 Android Manifest.xml 代码在这里...

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<uses-permission android:name="com.android.launcher.permission.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);
}

【讨论】:

  • 对不起。我检查了这段代码。我的应用程序快捷方式未删除。任何其他解决方案。
  • 就我的研究而言 - 没有:/
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-06-24
  • 1970-01-01
  • 1970-01-01
  • 2012-03-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多