• 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;
        }
  • 相关阅读:
    BZOJ 2752: [HAOI2012]高速公路(road)
    codevs 1979 第K个数
    洛谷 P2680 运输计划
    hdu 3501 Calculation 2
    POJ 2417 Discrete Logging
    比较数组和字典
    js事件之event.preventDefault()与event.stopPropagation()用法区别
    alert
    js基本类型的包装对象
    js取自定义data属性
  • 原文地址:https://www.cnblogs.com/yaxiaoke/p/5877263.html
Copyright © 2020-2023  润新知