首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在主屏幕中创建和删除应用程序快捷方式?

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

Stack Overflow用户
提问于 2012-06-13 20:35:53
回答 1查看 1.5K关注 0票数 1

我正在创建一个应用程序快捷方式。它运行良好。但是我不能删除这个快捷方式。如何删除我的应用程序快捷方式。在我的主页屏幕上包含了很多应用程序的快捷方式。如何删除它..

如果可能,请发送有关如何删除应用程序快捷方式的信息。否则,如果不可能,则发送原因。请回复您的答案和意见,这对我很有价值。谢谢。

我的示例代码在这里...

代码语言:javascript
复制
    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代码在这里...

代码语言:javascript
复制
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"/>
EN

回答 1

Stack Overflow用户

发布于 2012-06-13 20:44:25

这就是你要的

代码语言:javascript
复制
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);
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11014940

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档