Example #1
0
  private synchronized void compareAudioFiles() {
    //		Log.i("Test", "----------compareAudioFiles");
    if (null == mAudioCategory) {
      return;
    }
    String volumeName = "external";
    Uri uri = Audio.Media.getContentUri(volumeName);

    String[] columns =
        new String[] {
          BaseColumns._ID,
          MediaColumns.DATA,
          MediaColumns.DISPLAY_NAME,
          MediaColumns.SIZE,
          MediaColumns.DATE_ADDED,
          MediaColumns.DATE_MODIFIED,
          AudioColumns.DURATION,
          AudioColumns.ARTIST,
          AudioColumns.ALBUM,
          AudioColumns.ALBUM_ID,
          MediaColumns.MIME_TYPE,
          MediaColumns.TITLE
        };
    Cursor cur = null;
    try {
      cur =
          mContext
              .getContentResolver()
              .query(uri, columns, buildSelectionByCategory(TYPE_AUDIO), null, null);
      if (cur == null) {
        return;
      }

      if (!cur.moveToFirst()) {
        return;
      }
      compareFile(cur, mAudioCategory, mDeletedAudioList, TYPE_AUDIO);
    } catch (SQLiteException ex) {
      ex.printStackTrace();
    } finally {
      if (cur != null) {
        cur.close();
      }
    }
  }
Example #2
0
  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);
  }
Example #3
0
  /**
   * 获取专辑名称
   *
   * @param dbId
   * @return
   */
  public String getAlbumBucket(int dbId) {
    String volumeName = "external";
    String selection = BaseColumns._ID + "='" + dbId + "'";
    String[] columns = new String[] {AudioColumns.ALBUM};
    Uri uri = Audio.Media.getContentUri(volumeName);
    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, AudioColumns.ALBUM);
    } finally {
      if (cur != null) {
        cur.close();
      }
    }
  }
Example #4
0
  /**
   * 获取文件的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;
 }