@Override
 protected Cursor createCursor() {
   Cursor c =
       Images.Media.query(
           mContentResolver,
           mBaseUri,
           VIDEO_PROJECTION,
           whereClause(),
           whereClauseArgs(),
           sortOrder());
   return c;
 }
  private synchronized void compareImagesFiles() {
    //		Log.i("Test", "----------compareImagesFiles");
    if (null == mImageCategory) {
      return;
    }

    String volumeName = "external";
    Uri uri = Images.Media.getContentUri(volumeName);
    String[] columns =
        new String[] {
          BaseColumns._ID,
          MediaColumns.DATA,
          MediaColumns.DISPLAY_NAME,
          MediaColumns.SIZE,
          MediaColumns.DATE_ADDED,
          MediaColumns.DATE_MODIFIED,
          ImageColumns.BUCKET_DISPLAY_NAME,
          MediaColumns.MIME_TYPE
        };
    Cursor cur = null;
    try {
      cur =
          mContext
              .getContentResolver()
              .query(uri, columns, buildSelectionByCategory(TYPE_IMAGE), null, null);
      if (cur == null) {
        return;
      }

      if (!cur.moveToFirst()) {
        return;
      }

      compareFile(cur, mImageCategory, mDeletedImageList, TYPE_IMAGE);
    } catch (SQLiteException ex) {
      ex.printStackTrace();
    } finally {
      if (cur != null) {
        cur.close();
      }
    }
  }
  private void registerReceiver() {
    ContentResolver resolver = mContext.getContentResolver();
    String volumeName = "external";
    Uri uriAudio = Audio.Media.getContentUri(volumeName);
    mAudioObv = new ContentObserverAudio();
    resolver.registerContentObserver(uriAudio, true, mAudioObv);

    Uri uriImages = Images.Media.getContentUri(volumeName);
    mImagesObv = new ContentObserverImage();
    resolver.registerContentObserver(uriImages, true, mImagesObv);

    Uri uriVideo = Video.Media.getContentUri(volumeName);
    mVideoObv = new ContentObserverVideo();
    resolver.registerContentObserver(uriVideo, true, mVideoObv);

    mMediaScanReceiver = new MediaScanReceiver();
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
    filter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
    filter.addDataScheme("file");
    mContext.registerReceiver(mMediaScanReceiver, filter);
  }
  /**
   * 获取文件的MimeType
   *
   * @param dbId
   * @param type
   * @return
   */
  public String getMimeType(int dbId, int type) {
    String volumeName = "external";
    String selection = BaseColumns._ID + "='" + dbId + "'";
    String[] columns = new String[] {MediaColumns.MIME_TYPE};
    Uri uri = null;
    switch (type) {
      case TYPE_IMAGE:
        uri = Images.Media.getContentUri(volumeName);
        break;
      case TYPE_AUDIO:
        uri = Audio.Media.getContentUri(volumeName);
        break;
      case TYPE_VIDEO:
        uri = Video.Media.getContentUri(volumeName);
        break;
      default:
        break;
    }
    if (uri == null) {
      return null;
    }
    Cursor cur = null;
    try {
      cur = mContext.getContentResolver().query(uri, columns, selection, null, null);
      if (null == cur) {
        return null;
      }

      if (!cur.moveToFirst()) {
        return null;
      }
      return MediaDbUtil.getString(cur, MediaColumns.MIME_TYPE);
    } finally {
      if (cur != null) {
        cur.close();
      }
    }
  }
  public void refreshCategoryInfo() {
    // clear
    for (FileCategory fc : sCategories) {
      setCategoryInfo(fc, 0, 0);
    }

    // query database
    String volumeName = "external";

    Uri uri = Audio.Media.getContentUri(volumeName);
    refreshMediaCategory(FileCategory.Music, uri);

    uri = Video.Media.getContentUri(volumeName);
    refreshMediaCategory(FileCategory.Video, uri);

    uri = Images.Media.getContentUri(volumeName);
    refreshMediaCategory(FileCategory.Picture, uri);

    uri = Files.getContentUri(volumeName);
    refreshMediaCategory(FileCategory.Theme, uri);
    refreshMediaCategory(FileCategory.Doc, uri);
    refreshMediaCategory(FileCategory.Zip, uri);
    refreshMediaCategory(FileCategory.Apk, uri);
  }
 private Uri getContentUriByCategory(FileCategory cat) {
   Uri uri;
   String volumeName = "external";
   switch (cat) {
     case Theme:
     case Doc:
     case Zip:
     case Apk:
       uri = Files.getContentUri(volumeName);
       break;
     case Music:
       uri = Audio.Media.getContentUri(volumeName);
       break;
     case Video:
       uri = Video.Media.getContentUri(volumeName);
       break;
     case Picture:
       uri = Images.Media.getContentUri(volumeName);
       break;
     default:
       uri = null;
   }
   return uri;
 }
  public synchronized void initImage() {
    if (null == mImageCategory) {
      mImageCategory = new ConcurrentHashMap<String, Category>();
    }
    mImageCategory.clear();

    String volumeName = "external";
    Uri uri = Images.Media.getContentUri(volumeName);
    String[] columns =
        new String[] {
          BaseColumns._ID,
          MediaColumns.DATA,
          MediaColumns.DISPLAY_NAME,
          MediaColumns.SIZE,
          MediaColumns.DATE_ADDED,
          MediaColumns.DATE_MODIFIED,
          ImageColumns.BUCKET_DISPLAY_NAME,
          MediaColumns.MIME_TYPE
        };
    Cursor cur = null;
    try {
      cur =
          mContext
              .getContentResolver()
              .query(uri, columns, buildSelectionByCategory(TYPE_IMAGE), null, null);
      if (cur == null) {
        return;
      }

      if (!cur.moveToFirst()) {
        return;
      }

      do {
        ImageFile file = ImageFile.getInfo(cur);
        if (null == file) {
          continue;
        }
        // 取一张图片的路径,add by yangbing
        //				if (MediaOpenSettingConstants.sImagePath == null) {
        //					if (file.fullFilePath != null && !"".equals(file.fullFilePath)) {
        //						MediaOpenSettingConstants.sImagePath = file.fullFilePath;
        //					}
        //				}
        if (mImageCategory.containsKey(file.filePath)) {
          Category category = mImageCategory.get(file.filePath);
          category.addFile(file);
        } else {
          Category category = new Category();
          category.filePath = file.filePath;
          category.uri = category.filePath;
          category.alias = file.bucketName;
          category.init();
          category.addFile(file);
          mImageCategory.put(file.filePath, category);
        }
      } while (cur.moveToNext());
    } catch (SQLiteException e) {
      Log.e("FileEngine", "init image error");
    } finally {
      if (cur != null) {
        cur.close();
      }
    }
  }