android - 如何在主屏幕中创建和删除应用程序快捷方式?

标签 android

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

    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"/>

最佳答案

给你

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

关于android - 如何在主屏幕中创建和删除应用程序快捷方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11014940/

相关文章:

android - 如何使用 MediaCodec 对视频和音频进行编码

java - 操作栏在 Android 应用程序中显示为空

android - managed profile申请时如何获取主账号的包裹信息列表?

android - Android Service 和 Content Provider 的区别

java - Jsoup无法打开html页面Status=-1

android - 通过短信发送地址

android - 将项目导入 Android Studio 时缺少 setting.jar

android - 对话框中的控制音量 seekBar (AsyncTask)

android - 无法在 chrome 开发工具资源中调整列的大小

android - 在多模块项目android中集成onesignal