1、判断是否存在快捷方式:

title = ? 查询条件指的是创建快捷方式时设置的label字符串(Intent.EXTRA_SHORTCUT_NAME

    private boolean hasAddShortCut() {        boolean isInstallShortcut = false;        final ContentResolver cr = this.getContentResolver();        String AUTHORITY = "com.android.launcher2.settings";        final 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);        if (c != null && c.getCount() > 0) {            isInstallShortcut = true;        }        return isInstallShortcut;    }

2、创建快捷方式

    private void addShortCut(){        Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");        shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getResources().getString(R.string.app_name));        //设置是否可重复创建        shortcut.putExtra("duplicate", false);        //设置显示的图标        Parcelable icon = Intent.ShortcutIconResource.fromContext(this,R.mipmap.ic_launcher_mail);        shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,icon);        //点击快捷方式发起的intent的定义        Intent intent = new Intent(Intent.ACTION_MAIN);        intent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);        intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);        intent.addCategory(Intent.CATEGORY_LAUNCHER);        //对于使用activity-alias控件的请用setClassName接口来设置启动的activity</span>        //intent.setClass(MailActivityEmail.this, MailActivityEmail.class);        intent.setClassName("com.kingsoft.email","com.kingsoft.email.activity.Welcome");        shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);        this.sendBroadcast(shortcut);    }




更多相关文章

  1. android获取控件宽度
  2. Android 自定义控件之ViewPager Indicator实现方式
  3. Android 创建一个包含星期的格式字符串
  4. Android源码快速查找文件、搜索字符串和编译
  5. android仿iPhone滚轮控件实现及源码
  6. Android中的webView控件实现网页缩放
  7. android上传图片以及POST字符串
  8. Android 自定义控件实现点击波浪效果(九)
  9. 第八篇 TabHost控件

随机推荐

  1. Javascript中的素数函数...多个语句
  2. [Effective JavaScript 笔记]第65条:不要
  3. 如何在chart.js中为饼图添加标签
  4. 禁用Chrome严格的MIME类型检查
  5. JavaScript正则表达式定义字符集
  6. 用npm-run自动化任务
  7. “错误:路径必须是字符串”(v5.10.0)
  8. 放在和中的javascript语句,但是语句不在函
  9. 使用php Ajax在数据库中插入动态数据
  10. 打字稿:无法访问类属性[重复]