「已注销」 2018-09-16 12:21 采纳率: 0%
浏览 838

android6.0以后怎么删除快捷方式?

private void createShortCut() {
    Log.i("TAG", "创建快捷方式");
    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));
    Intent.ShortcutIconResource icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher);
    shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
    shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, getShortCutIntent());
    sendBroadcast(shortcutintent);
}

private void delectShortCut() {
    Log.i("TAG", "删除快捷方式");
    Intent shortcut = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));

    shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, getShortCutIntent());
    sendBroadcast(shortcut);

}

private Intent getShortCutIntent() {
    Intent intent = new Intent();
    intent.setClass(this, this.getClass());
    /*以下两句是为了在卸载应用的时候同时删除桌面快捷方式*/
    intent.setAction("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.LAUNCHER");
    return intent;
}

权限:

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

模拟器测试5.0 可以正常创建和删除快捷方式;6.0以后可以创建,但是调用delectShortCut(),却删除不了快捷方式。求解

  • 写回答

3条回答 默认 最新

  • devmiao 2018-09-16 16:05
    关注
    评论

报告相同问题?

悬赏问题

  • ¥30 dspbuilder中使用signalcompiler时报错Error during compilation: Fitter failed,求解决办法
  • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题