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 ...
随机推荐
- 计算机网络(8)-----TCP报文段的首部格式
TCP报文段的首部格式 概述 TCP报文段首部的前20个字节是固定的,因此TCP首部的最小长度是20字节. 源端口和目标端口 各占2个字节,分别写入源端口号和目的端口号. 序列号 占4个字节,表示本报 ...
- android 混淆导致友盟反馈出错
最近混淆应用时出现了一个错误: 打包编译没问题,但程序运行之后,点击友盟的反馈就会导致程序报错: E/AndroidRuntime(7669): java.lang.RuntimeException ...
- Python Day04
一.迭代器与生成器: 迭代器(iterator): 迭代器是访问集合元素的一种方式.迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束.迭代器只能往前不会后退,迭代器的一大优点是不要求事 ...
- Mysql数据库的一些命令_LInux
查看当前数据库的版本,因为有些命令在不同版本中 用法有可能不一样,注意 -V 是大写字母V[root@localhost ~]# mysqladmin -Vmysqladmin Ver 8.42 D ...
- 进程间通信--fork函数
#include <unistd.h> pid_t fork(void); fork() creates a new process by duplicating the calling ...
- JS数组中every(),filter(),forEach(),map(),some()方法学习笔记!
ES5中定义了五种数组的迭代方法:every(),filter(),forEach(),map(),some(). 每个方法都接受两个参数:要在每一项运行的函数(必选)和运行该函数的作用域的对象-影响 ...
- 杭电ACM1001
原题:http://acm.hdu.edu.cn/showproblem.php?pid=1001 #include <stdio.h> int main(void) { int i,n, ...
- jQuery---中的动画
show():$('p').show(); show(1000) 里面加参数会让元素在显示的时候动起来 hide():$('p').hide(); hide(1000) 里面加参数让元素在隐藏的时候动 ...
- JDBC driver connection string大全
Database / data source URL format / driver name Value Default port MySQL URL format: jdbc:mysql: ...
- DotSpatial 删除图层要素
//添加图层后,定义图层,并获取图层 //遍历要素,并进行删除 FeatureSet fs = null; fs = (FeatureSet) map1.Layers[0].DataSet; //要素 ...