大家帮忙看看,怎么判断不了到底有没创建快捷方式啊 ,每次都弹窗口显示是否创建快捷方式 ,怎么回事啊?
谢谢各位帅哥美女们了,I Love U....  
无关代码我都打斜线注释了啊  我已经创建了快捷方式的时候 也弹对话框 郁闷死了 拜托大家了
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //initService();
        setContentView(R.layout.main_tab);
        
        //创建快捷方式
        if(isInstallShortcut()==false){
                showDialog();
              }
       // mTabHost = getTabHost();
        //driverName = Build.MODEL;
        //setupTabsEmpty();
        // setupTabs();        //initProgress();
        //checkVersion();
        
        
    }
   
//弹出是否创建快捷方式对话框
    private void showDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        builder.setTitle(getResources().getString(R.string.ma_shorcut_title))
        .setMessage(getResources().getString(R.string.ma_addorno_sc))
        .setPositiveButton(getResources().getString(R.string.ok), new OnClickListener() {
            
            public void onClick(DialogInterface dialog, int which) {
                addShortcut();
            }
        }).setNegativeButton(getResources().getString(R.string.cancel), null).create().show();
    }    //在桌面添加快捷方式
    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);
        
        ComponentName comp = new ComponentName(this.getPackageName(), "."+this.getLocalClassName());
        shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));
        
        ShortcutIconResource iconResource = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
        shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
        sendBroadcast(shortcut);
    }    //判断是否存在快捷方式
    private boolean isInstallShortcut() {
        ContentResolver contentResolver = this.getContentResolver();
          String authority = "com.android.launcher.settings";
          Uri content_uri = Uri.parse("content://" + authority + "/favorites?notify=true");
          Cursor cursor = contentResolver.query(content_uri, new String[] {"title", "iconResource"}, "title=?",
                  new String[]{MainActivity.this.getResources().getString(R.string.app_name)}, null);
          if(cursor != null && cursor.getCount() > 0){
           return  true;
          }else{
           return false;
          }
    }

解决方案 »

  1.   

    cursor 你创建完之后还是0?
      

  2.   

    你确定你的query 语句写的没问题?如果cursor 不为 null。 函数返回的时候一定关闭cursor哦if(cursor != null){
       try{
            //do something.
      

  3.   

    你确定你的query 语句 写对了的?还有cursor 如果不为空,一定要记得关闭啊
    if(cursor != null}{
       try{
             //do something.
          }finally{
             cursor.close();
          }
    }}
      

  4.   

    private void addShortcut() 方法里若添加快捷方式成功应该存一下
    private boolean isInstallShortcut() 方法查询出来才不为空,才会返回true
    还有这个“/favorites?notify=true“什么意思?