zoukankan      html  css  js  c++  java
  • 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;
        }
  • 相关阅读:
    Html禁止粘贴 复制 剪切
    表单标签
    自构BeanHandler(用BeansUtils)
    spring配置中引入properties
    How Subcontracting Cockpit ME2ON creates SD delivery?
    cascadia code一款很好看的微软字体
    How condition value calculated in sap
    Code in SAP query
    SO Pricing not updated for partial billing items
    Javascript learning
  • 原文地址:https://www.cnblogs.com/yaxiaoke/p/5877263.html
Copyright © 2011-2022 走看看