添加删除桌面图标 android怎样添加桌面图标和卸载程序后自动删除图标

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

添加删除桌面图标 android怎样添加桌面图标和卸载程序后自动删除图标

  2021-03-18 我要评论
想了解android怎样添加桌面图标和卸载程序后自动删除图标的相关内容吗,在本文为您仔细讲解添加删除桌面图标的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:桌面,创建图标,下面大家一起来学习吧。
1:创建图标如下
复制代码 代码如下:

Intent intent = new Intent();
intent.setClass(this, SplashActivity.class);
Intent addShortcut = new Intent(ACTION_ADD_SHORTCUT);
Parcelable icon = Intent.ShortcutIconResource.fromContext(this,
R.drawable.icon);
addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
addShortcut.putExtra("duplicate", 0);
addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
sendBroadcast(addShortcut);

2:删除图标如下
复制代码 代码如下:

Intent intent = new Intent();
intent.setClass(this, SplashActivity.class);
intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
Intent addShortcut = new Intent(ACTION_ADD_SHORTCUT);
Parcelable icon = Intent.ShortcutIconResource.fromContext(this,
R.drawable.icon);
addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
addShortcut.putExtra("duplicate", 0);
addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
sendBroadcast(addShortcut);
intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");

需要两个过滤属性

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们