在android应用启动时中我写了个判断快捷方式的方法,但是它总是返回false,并不会返回true,请问下我哪里写错了吗?
谢谢各位了!
代码如下: private boolean isFavorites() {
boolean isInstallShortcut = false;
final ContentResolver cr = getContentResolver();
final String AUTHORITY = "com.android.launcher.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;
}

解决方案 »

  1.   

    getString(R.string.app_name)
    这个名称你改改,手动写,不行就试试packagename
      

  2.   

    请问上面的代码有错误吗?
    我是想先判断有没有这个快捷方式存在,如果存在就不创建,不存在则创建。
    虽然我是用的中文,但是android系统它为什么能创建并提示出来呢?其实我就想把android系统创建快捷方式的时候那个提示给去掉,请问有什么办法吗?再次谢谢了!
      

  3.   

    下面是我创建快捷方式的时候的代码,请帮我看看是否和判断快捷方式的地方有冲突了。谢谢了private void addShortcut() {
    Intent shortcut = new Intent(
    "com.android.launcher.action.INSTALL_SHORTCUT"); // 快捷方式的名称
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,
    getString(R.string.app_name));
    shortcut.putExtra("duplicate", false); // 不允许重复创建 // 指定当前的Activity为快捷方式启动的对象: 如 com.everest.video.VideoPlayer
    // 注意: ComponentName的第二个参数必须加上点号(.),否则快捷方式无法启动相应程序
    ComponentName comp = new ComponentName(this.getPackageName(), "."
    + this.getLocalClassName());
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(
    Intent.ACTION_MAIN).setComponent(comp)); // 快捷方式的图标
    Intent.ShortcutIconResource iconRes = Intent.ShortcutIconResource
    .fromContext(this, R.drawable.icon);
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
    sendBroadcast(shortcut);
    }
      

  4.   

    总结的关于添加和删除及判断是否存在快捷方式,Android应用添加(创建)和删除及判断是否存在桌面快捷方式
      

  5.   

    都不行,,,,系统发布方 重定向了 ReadSetting 的地址,需要发布方的权限才行,通用不了,,,,
      

  6.   

    final String AUTHORITY = "com.android.launcher.settings"; 
    改成
    final String AUTHORITY ="com.android.launcher2.settings";试试