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 ... 
随机推荐
- SharePoint 2010 + 左侧导航(Left Nav Bar)二级菜单的修改
			SharePoint 2010 + 修改左侧导航类似顶部导航菜单的样式 查找aspmenu的控件,ID为“V4QuickLaunchMenu”,修改分别将属性“StaticDisplayLevels” ... 
- Android Studio打开时提示ADB错误的问题
			如图所示,ADB连接错误,解决办法很简单:打开cmd,定位到sdk文件夹下的platform-tools,然后执行adb kill-server回车:再执行adb start-server即可 
- win10 Unistack 服务组 占用资源如何解决
			开始菜单>设置>隐私,隐私界面的左侧栏目,找最后一个“后台应用”,把后台运行的应用全部关掉即可 
- js③
			while(true){ console.log('hello'); }/每次执行完语句块之后,又会跳回去检查小括号里面的布尔值,如果为true,那么又会执行语句块一次. //while循环//var ... 
- Bootstrap v4.0.0-alpha.5 发布,大量更新
			Bootstrap v4.0.0-alpha.5 发布了,Bootstrap是快速开发Web应用程序的前端工具包.它是一个CSS和HTML的集合,它使用了最新的浏览器技术,给你的Web开发提供了时尚的 ... 
- 微信Auth2.0授权的时候出现两次回调
			在获取用户OpenID的时候 $url="https://open.weixin.qq.com/connect/oauth2/authorize?appid=".WX_APPID. ... 
- sqlite的常用语法
			sqllite 增删改查创建表的语法 创建表db.execSQL("create table user(_id integer primary key autoincrement,numbe ... 
- Spark源码学习1.7——Master.scala
			master第一步是加载系统定义的环境变量,如worker的超时时间.系统保留的Application数目等:第二步,加载worker的信 息,地址.id等:第三步,加载Application的信息, ... 
- 遗传算法的C语言实现(一):以非线性函数求极值为例
			以前搞数学建模的时候,研究过(其实也不算是研究,只是大概了解)一些人工智能算法,比如前面已经说过的粒子群算法(PSO),还有著名的遗传算法(GA),模拟退火算法(SA),蚁群算法(ACA)等.当时懂得 ... 
- Ubuntu gcc缺失问题
			在安装redis过程中,需要使用make编译源码,但发现linux中缺失gcc,系统为Ubuntu12. 一般情况下,可使用sudo apt-get install gcc或者sudo apt-get ... 
