【问题标题】:Android : Remove all shortcuts associated with the app from codeAndroid:从代码中删除与应用程序关联的所有快捷方式
【发布时间】:2013-05-31 23:31:22
【问题描述】:

我想在单击按钮等单个事件时删除我的应用主屏幕上的所有快捷方式。 有没有办法做到这一点?或者至少从我的应用程序中获取放置在主屏幕上的所有快捷方式的显示名称? (在创建快捷方式时,我不能在任何共享首选项/数据库中使用它,因为用户甚至可以执行“清除数据”)

【问题讨论】:

    标签: android installation uninstallation shortcut homescreen


    【解决方案1】:

    试试这个:

    appShortcutIntent = new Intent();
    appShortcutIntent.setClassName("com.pkg.pkgname", "MainActivity");
    appShortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    
    appIcon = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
    
    Intent intentDeleteShortcut = new Intent();
    intentDeleteShortcut.putExtra("android.intent.extra.shortcut.INTENT", appShortcutIntent);
    intentDeleteShortcut.putExtra("android.intent.extra.shortcut.NAME", getResources().getString(R.string.app_name));
    intentDeleteShortcut.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", appIcon);
    intentDeleteShortcut.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
    sendBroadcast(intentDeleteShortcut);
    

    并在清单文件中添加此权限:

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

    希望这会有所帮助。

    (PS:据我所知,这将需要设备植根。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-22
      • 2021-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-02
      相关资源
      最近更新 更多