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;
        }
  • 相关阅读:
    [USACO14DEC] Cow Jog_Gold 牛慢跑(金)题解
    [USACO16DEC]Moocast(gold)奶牛广播-金 题解
    [USACO17FEB]Why Did the Cow Cross the Road III S题解
    [USACO4.3]逢低吸纳Buy Low, Buy Lower题解
    洛谷P5057 [CQOI2006]简单题题解
    ksum及二维版本
    [Noip2015] 信息传递
    数据库常用操作
    解决Mac连接MySQL需要输入绝对路径的问题
    在MAC上安装OpenCV(C++)
  • 原文地址:https://www.cnblogs.com/yaxiaoke/p/5877263.html
Copyright © 2011-2022 走看看