Android的:如何从主屏幕中删除/卸载应用程序快捷方式? [英] Android: How to Remove/Uninstall application shortcuts from Home Screen?

查看:420
本文介绍了Android的:如何从主屏幕中删除/卸载应用程序快捷方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力(ADD,然后)从主屏我的应用程序的快捷方式。 添加快捷键的作品完美但是我不能删除我用下面code创建的快捷方式。

 公共无效setupShortCut(布尔创建){
        shortcutIntent =新意图();
        shortcutIntent.setClassName(com.abc.xyz,XYZActivity);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        图标= Intent.ShortcutIconResource.fromContext(这一点,R.drawable.icon);

        意图int​​entShortcut =新意图();
        intentShortcut.putExtra(android.intent.extra.shortcut.INTENT,shortcutIntent);
        intentShortcut.putExtra(android.intent.extra.shortcut.NAME,getResources()的getString(R.string.app_name));
        intentShortcut.putExtra(android.intent.extra.shortcut.ICON_RESOURCE,图标);
        如果(创建){
          intentShortcut.setAction(com.android.launcher.action.INSTALL_SHORTCUT);
        } 其他 {
        intentShortcut.setAction(com.android.launcher.action.UNINSTALL_SHORTCUT);
        }
        sendBroadcast(intentShortcut);
    }
 

请建议我在哪里的问题呢?

修改1:

我所需的权限在我的清单文件:

 <使用-权限的Andr​​oid:名称=com.android.launcher.permission.UNINSTALL_SHORTCUT/
 

解决方案

想通了根本原因: - )

我想通了,为什么它不是为我工作的原因。 我使用的是不同的第三方启动器(比普通的Andr​​oid发射器等)在我的手机。 创建和删除一个程序 - 快捷方式工作,只要您使用支持该操作的发射器。 我跑了默认启动上述code和它的工作原理就像一个魅力:)

感谢大家对您的答复!

I have been trying to (ADD and then) REMOVE my APP's shortcut from HOME-SCREEN. ADDING a shortcut works perfectly however I'm not able to remove the shortcut I've created using below code.

public void setupShortCut(boolean create) {
        shortcutIntent = new Intent();
        shortcutIntent.setClassName("com.abc.xyz", "XYZActivity");
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);

        Intent intentShortcut = new Intent();
        intentShortcut.putExtra("android.intent.extra.shortcut.INTENT", shortcutIntent);
        intentShortcut.putExtra("android.intent.extra.shortcut.NAME", getResources().getString(R.string.app_name));
        intentShortcut.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", icon);
        if(create) {
          intentShortcut.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        } else {
        intentShortcut.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
        }
        sendBroadcast(intentShortcut);
    }

Please suggest where am I going wrong?

EDIT 1:

I have required permission in my Manifest file:

<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" /

解决方案

FIGURED OUT THE ROOT CAUSE :-)

I figured out the reason why it wasn't working for me. I am using a different 3rd party launcher (other than Stock android launcher) on my phone. CREATING and REMOVING an App-Shortcut works as long as the launcher you are using supports that operation. I ran the above code on default launcher and it works like a charm :)

Thank you everyone for your replies!

这篇关于Android的:如何从主屏幕中删除/卸载应用程序快捷方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆