public class ShortcutUtil {
/**
* 创建快捷方式
*
* @param context
*/
public static void createShortcut(Context context, Class<?> target) {
// <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.icon));
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, context.getString(R.string.app_name));
intent.putExtra("duplicate", false);
Intent sIntent = new Intent(Intent.ACTION_MAIN);
sIntent.addCategory(Intent.CATEGORY_LAUNCHER);// 加入action,和category之后,程序卸载的时候才会主动将该快捷方式也卸载
sIntent.setClass(context, target);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, sIntent);
context.sendBroadcast(intent);
}
/**
* 判断桌面上是否有的快捷方式
*
* @return
*/
public static boolean hasShortcut(Context context) {
final ContentResolver cr = context.getContentResolver();
final String AUTHORITY = "com.android.launcher.settings";
final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/favorites?notify=true");
// <uses-permission android:name="com.android.launcher.permission.READ_SETTINGS"/>
Cursor c = cr.query(CONTENT_URI, new String[] { "intent" }, null, null, null);
if (c == null) {
// 注: 2.1update和2.2版本的真机上测试无法访问com.android.launcher.settings,2.1update1的模拟器上可以
// ERROR/ActivityThread(1136): Failed to find provider info for com.android.launcher.settings
return false;
}
while (c.moveToNext()) {
String intentstring = c.getString(c.getColumnIndex("intent"));
if (intentstring == null) {
continue;
}
String componentString = getComponentString(intentstring);
if (componentString.startsWith(context.getPackageName())) {
return true;
}
}
return false;
}
private static String getComponentString(String intentInfo) {
// intent info 的格式:intent=#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.allstar.tanzhi/.activities.StartActivity;end
int start = intentInfo.indexOf("component") + 9 + 1;
int end = intentInfo.indexOf(";", start);
return intentInfo.substring(start, end);
}
分享到:
相关推荐
android 检查是否创建桌面快捷方式以及创建快捷方式
Android判断是否获取到桌面快捷方式权限
里面的工具类是 通过 各自的实现来判断 华为,小米 oppo vivi等的应用是否 拥有快捷方式 的权限,如果没有的话,则需要去手动授权。
当用户打开App时,检测是否已创建快捷方式。若已创建,直接进入;若未创建,弹窗提示用户创建
在每章的讲解中,它会让你通过一系列示例项目逐步掌握Android中的各种新功能和技术,助你取得最圆满的学习效果。本书所介绍的各个应用实例简明扼要且极具实用价值,它们覆盖了Android 1.0的所有基本功能和高级功能...
6.4 Android中的数据库 6.4.1 SQLite简介 6.4.2 Cursor和内容值 6.4.3 使用Android数据库 6.5 内容提供器简介 6.5.1 使用内容提供器 6.5.2 本地Android内容提供器 6.5.3 创建一个新的内容提供器 6.5.4 创建和使用...
需要权限: com.android.launcher.permission.INSTALL_SHORTCUT 检测是否存在快捷键 为程序创建桌面快捷方式 删除程序的快捷方式
14.3.1 在桌面上创建快捷方式 532 14.3.2 向Launcher添加快捷方式 534 14.4 管理桌面小控件 535 14.5 实时文件夹(LiveFolder) 539 14.5.1 使用实时文件夹显示 ContentProvider的数据 540 14.6 本章...
Android实例源码-应用启动应用退出&网络判断类...快捷图标的创建与移除 网络判断,界面启动 网络连接状态检测 获取手机应用信息 返回键退出程序的两种方式 闪屏加退出提示应用 隐藏安装包图标使用其他应用启动本应用
14.3.1 在桌面上创建快捷方式 532 14.3.2 向Launcher添加快捷方式 534 14.4 管理桌面小控件 535 14.5 实时文件夹(LiveFolder) 539 14.5.1 使用实时文件夹显示 ContentProvider的数据 540 14.6 本章小结 545 第15章...
目前市场业务中在产品以及其他项目的认证和检测方面存在诸多不便,用户需要实地考察并频繁与检测单位沟通,填写繁琐的纸质检测报告、当面送递样品,对于检测环节中存在的问题难以及时交互并处理。市场上相应的检测...
3.在检测到运动时录制视频(在设置中设置视频录制长度:分割录制时间:最大录制时间) “绿色大按钮” - 按下它,运动检测将启动。确保设备稳定并且有足够的光线。 “大橙色按钮” - 连续快照模式。重复捕捉图像。 ...
在主屏幕上创建1-tap Booster快捷方式,以更有效地加快电话速度。MAX Booster清理手机。 带有AVTEST认证的#1引擎的移动安全和免费杀毒软件MAX Security杀毒软件(适用于android的病毒清除器)提供了可靠的...
轻松处理存储在外部SD卡上的所有文件/文件夹:浏览,复制,粘贴,移动,删除,搜索,压缩,解压缩,创建新的,共享,排序,创建快捷方式,多选,检测大文件... -App Manager *将内部存储应用程序移动到外部SD卡,为...
- 在 HOME 应用中创建快捷图标。 - 自定快捷键的绑定。 - Gingerbread 样式的文本选择。(轻触两下选择单词,再次轻触选定的区域可显示标记。) - 自动换行开关以及自动换行宽度的设置。 - 设定制表符宽度。 - ...
-其有着强大用于翻译验证的QA功能,能帮助解决一些翻译过程中的一般性错误,诸如忘记的菜单快捷方式,错误的占位符数目,甚至一些在翻译过程中尚未发生的错误。 -其报表与统计功能使得用户能实时掌握本地化的状态与...
A 新增 云开发环境中的存储桶被删除时,支持在云控制台中创建存储桶 A 新增 新建 Page 失败后会给出失败提示 A 新增 JSServer 支持文件 diff A 新增 不再存储 project.config.json 里自定义编译条件的 current 值...