Android添加快捷方式
private void addShortcutToDesktop() {
Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
// 不允许重建
shortcut.putExtra("duplicate", false);
// 设置名字
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,getString(R.string.app_name));// 桌面快捷方式名称
// 设置图标
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(this,R.mipmap.ic_launcher));
// 设置意图和快捷方式关联程序
Intent intent = new Intent(this, this.getClass());
// 桌面图标和应用绑定,卸载应用后系统会同时自动删除图标
intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
// 发送广播
sendBroadcast(shortcut);
}
private boolean isShortcutInstalled() {
boolean isInstallShortcut = false;
final ContentResolver cr = this.getContentResolver();
// 2.2系统是”com.android.launcher2.settings”,网上见其他的为"com.android.launcher.settings"
String AUTHORITY = null;
/*
* 根据版本号设置Uri的AUTHORITY
*/
// if (getSystemVersion() >= 8) {
AUTHORITY = "com.android.launcher2.settings";
// } else {
// AUTHORITY = "com.android.launcher.settings";
// }
Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/favorites?notify=true");
Cursor c = cr.query(CONTENT_URI,
new String[] { "title", "iconResource" }, "title=?",
new String[] { getString(R.string.app_name) }, null);// 这里得保证app_name与创建
//快捷方式名的一致,否则会出现提示“快捷方式已经创建”
if (c != null && c.getCount() > 0) {
isInstallShortcut = true;
}
return isInstallShortcut;
}
Android添加快捷方式的更多相关文章
- Android添加快捷方式(Shortcut)到手机桌面
Android添加快捷方式(Short)到手机桌面 权限 要在手机桌面上添加快捷方式,首先需要在manifest中添加权限. <!-- 添加快捷方式 --> <uses-permis ...
- Android添加桌面快捷方式的简单实现
核心代码如下: Button bn = (Button) findViewById(R.id.bn); // 为按钮的单击事件添加监听器 bn.setOnClickListener(new OnCli ...
- android 添加桌面快捷方式
.在桌面创建快捷方式方法: 方法一:通过长按某一个应用程序的图标在桌面上创建启动该应用程序的快捷方式. 这个方法安装完程序都用户都能实现. 方法二:在应用程序中构建一个Intent,然后以Broadc ...
- VC/Wince 实现仿Win8 Metro风格界面3——按钮移动交换、删除、添加快捷方式(附效果图)
上一篇文章写了如何进行页面滑动切换,今天我讲一下如何实现两个按钮拖动交换位置,包括同一个页面按钮交换或者两个页面之间的按钮交换.另外就是如何拖动删除界面上的快捷方式.按钮交换和拖动删除,这两个功能基本 ...
- android 添加依赖的库文件
Notpad: 2016-3-16: 1.android 添加依赖的库文件 右键自己的项目 -> properties ->android ->在Library处点击add -> ...
- Android 添加网络权限
[Android 添加网络权限] <uses-permission Android:name="android.permission.INTERNET"></us ...
- Ubuntu安装spyder并添加快捷方式
Ubuntu安装spyder并添加快捷方式 之前通过 sudo apt install spyder sudo apt install spyder3 安装spyder,但是这样有个坏处,编译器只能用 ...
- Android 添加framework资源包
为Android系统添加一个新的资源包 概述 传统的Android系统只有一个framework-res.apk资源包,第三方厂商在进行rom定制时会直接修改framework res资源,达到适配目 ...
- Android 添加键值并上报从驱动到上层
转载:https://blog.csdn.net/weixin_43854010/article/details/94390803 Android 添加键值并上报从驱动到上层 平台 :RK3288 O ...
随机推荐
- C# MD5加密
public static string Encrypt(string txt) { System.Security.Cryptography.MD5CryptoServiceProvider md5 ...
- 个人纪录(初)----Ueditor文本编辑器的引用
源码下载地址:http://ueditor.baidu.com/website/ 打开源码参考.html 把ueditor引入自己的web项目下. 在需要引入文本的地方写个div,设置样式等. 并且在 ...
- SQL Server数据库性能优化之SQL语句篇【转】
SQL Server数据库性能优化之SQL语句篇http://www.blogjava.net/allen-zhe/archive/2010/07/23/326927.html 近期项目需要, 做了一 ...
- spout详解
spout放在每个executer执行,我们先从spoutExecutors的初始化开始往下看,spoutExecutors是在一个worker中管理其中的tasks,在SpoutExecutors的 ...
- 一个简单的金额平均分配函数(C#版)
//总金额平均分配给总人数 //参数说明:总金额,总人数,最大金额为平均金额的倍率 public double[] GetList(double zje,int zrs,int max) { doub ...
- Ftrl in tensorflow
reference :点击这里https://github.com/tensorflow/tensorflow/issues/3725 讲解 http://www.tuicool.com/articl ...
- aspx文件为什么会慢
你可以在 global.asax 的 Application_Start 方法中写一个日志,例如写 C# code ? 1 2 3 4 5 void Application_Start(objec ...
- oracle分析函数与over()(转)
文章参考:http://blog.csdn.net/haiross/article/details/15336313 -- Oracle分析函数入门-- 分析函数是什么? 分析函数是Oracle专门用 ...
- wp8开发笔记之应用程序真机发布调试
写在前面的话: 相信很多和我一样关注wp8动态以及已经开发了一些wp8应用程序的朋友们都遇到过这样的问题,写的程序在模拟器上进行调试总是显的没什么说服力,想拿真机进行实际测试, 该怎么办才好呢? 进行 ...
- Visual C# 代码段
代码段是现成的代码段,您可以快速将其插入到您的代码中. 例如,for 代码段创建一个空的 for 循环. 有些代码段为外侧代码段,这些代码段允许您先选择代码行,然后选择要并入选定代码行的代码段. 例如 ...