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添加快捷方式的更多相关文章

  1. Android添加快捷方式(Shortcut)到手机桌面

    Android添加快捷方式(Short)到手机桌面 权限 要在手机桌面上添加快捷方式,首先需要在manifest中添加权限. <!-- 添加快捷方式 --> <uses-permis ...

  2. Android添加桌面快捷方式的简单实现

    核心代码如下: Button bn = (Button) findViewById(R.id.bn); // 为按钮的单击事件添加监听器 bn.setOnClickListener(new OnCli ...

  3. android 添加桌面快捷方式

    .在桌面创建快捷方式方法: 方法一:通过长按某一个应用程序的图标在桌面上创建启动该应用程序的快捷方式. 这个方法安装完程序都用户都能实现. 方法二:在应用程序中构建一个Intent,然后以Broadc ...

  4. VC/Wince 实现仿Win8 Metro风格界面3——按钮移动交换、删除、添加快捷方式(附效果图)

    上一篇文章写了如何进行页面滑动切换,今天我讲一下如何实现两个按钮拖动交换位置,包括同一个页面按钮交换或者两个页面之间的按钮交换.另外就是如何拖动删除界面上的快捷方式.按钮交换和拖动删除,这两个功能基本 ...

  5. android 添加依赖的库文件

    Notpad: 2016-3-16: 1.android 添加依赖的库文件 右键自己的项目 -> properties ->android ->在Library处点击add -> ...

  6. Android 添加网络权限

    [Android 添加网络权限] <uses-permission Android:name="android.permission.INTERNET"></us ...

  7. Ubuntu安装spyder并添加快捷方式

    Ubuntu安装spyder并添加快捷方式 之前通过 sudo apt install spyder sudo apt install spyder3 安装spyder,但是这样有个坏处,编译器只能用 ...

  8. Android 添加framework资源包

    为Android系统添加一个新的资源包 概述 传统的Android系统只有一个framework-res.apk资源包,第三方厂商在进行rom定制时会直接修改framework res资源,达到适配目 ...

  9. Android 添加键值并上报从驱动到上层

    转载:https://blog.csdn.net/weixin_43854010/article/details/94390803 Android 添加键值并上报从驱动到上层 平台 :RK3288 O ...

随机推荐

  1. Fibonacci(斐波那契)非递归实现。容易看懂

    #include<iostream>using namespace std;int main(){ int n; cout<<"please input a n\n& ...

  2. RN的像素及布局

    转自:http://www.cocoachina.com/ios/20150420/11608.html 宽度单位和像素密度 react的宽度不支持百分比,设置宽度时不需要带单位 {width: 10 ...

  3. int->string-------------c

    void intToString(int n,char a[]){ int i=1,m=n; while((n/=10)!=0)  i++; int j=0; for(;j<i;j++){  a ...

  4. SQL表旋转

    在制作报表的时候,有时候会碰到基础资料是依照时间区间去一笔一笔记录的资料,但是使用者在看报表的时候想要将时间区间以横向的方式呈现不是直向的情况出现,又或者基础资料的表数据结构是横向的而使用者在看报表的 ...

  5. 例子:Basic Lens sample

    本例演示了如何自己扩展一个Camera Lens. 1. UI界面是一个MediaViewer <controls:MediaViewer x:Name="MediaViewer&qu ...

  6. 非Animal呢?为何不写个万用类

    /*4.非Animal呢?为何不写个万用类 * 类Object是JAVA里多有类的源头/父类*/ import java.util.*; class Animalb{ String name; voi ...

  7. linux 常用操作指令(随时更新)

    ls: 查看当前目录下文件列表 -l   列出文件详细信息l(list)  -a   列出当前目录下所有文件及目录,包括隐藏的a(all) mkdir         创建目录 -p         ...

  8. 应用间共享数据方法(一)---sharepreferce

    SharedPreferences类,它是一个轻量级的存储类,特别适合用于保存软件配置参数. SharedPreferences保存数据,其背后是用xml文件存放数据,文件存放在/data/data/ ...

  9. 第二篇——The communication during software engineering.

    I've learned a lot in my software engineering class about how a program comes out.That's also a esse ...

  10. 简单方便的div垂直居中。

    此处讨论的是,在一个父容器中只有一个DIV,这个DIV相对于父元素垂直居中的问题: 以下列举三种方式:这里为了层次清晰,都是采用的sass写法. 一:适用于子元素有具体的宽高 .wrap{ //父元素 ...