示例#1
0
  private static Media getLastImageThumbnail(ContentResolver resolver) {
    Uri baseUri = Images.Media.EXTERNAL_CONTENT_URI;
    Log.d("mk", "getLastImageThumbnail() = " + baseUri.toString());
    Log.d("mk", "DCIM = " + Storage.DCIM.toString());
    Uri query = baseUri.buildUpon().appendQueryParameter("limit", "1").build();
    String[] projection =
        new String[] {ImageColumns._ID, ImageColumns.ORIENTATION, ImageColumns.DATE_TAKEN};
    String selection =
        ImageColumns.MIME_TYPE
            + "='image/jpeg'"
            + "AND "
            + ImageColumns.BUCKET_ID
            + "="
            + Storage.getBucketId(Storage.FILE_TYPE_PHOTO);
    // ImageColumns.BUCKET_DISPLAY_NAME + "='Photo'";
    String order = ImageColumns.DATE_TAKEN + " DESC," + ImageColumns._ID + " DESC";

    Cursor cursor = null;
    try {
      cursor = resolver.query(query, projection, selection, null, order);
      if (cursor != null && cursor.moveToFirst()) {
        long id = cursor.getLong(0);
        return new Media(
            id, cursor.getInt(1), cursor.getLong(2), ContentUris.withAppendedId(baseUri, id));
      }
      Log.d("dyb", "cursor null");
    } finally {
      if (cursor != null) {
        cursor.close();
      }
    }
    return null;
  }
示例#2
0
  private static Media getLastVideoThumbnail(ContentResolver resolver) {
    Uri baseUri = Video.Media.EXTERNAL_CONTENT_URI;
    Log.d("mk", "getLastVideoThumbnail() = " + baseUri.toString());
    Uri query = baseUri.buildUpon().appendQueryParameter("limit", "1").build();
    String[] projection =
        new String[] {VideoColumns._ID, MediaColumns.DATA, VideoColumns.DATE_TAKEN};
    // String selection = ImageColumns.BUCKET_DISPLAY_NAME + "='Video'";
    String selection =
        "("
            + ImageColumns.MIME_TYPE
            + "='video/3gpp'"
            + "OR "
            + ImageColumns.MIME_TYPE
            + "='video/mp4'"
            + ")"
            + "AND "
            + ImageColumns.BUCKET_ID
            + "="
            + Storage.getBucketId(Storage.FILE_TYPE_VIDEO);

    String order = VideoColumns.DATE_TAKEN + " DESC," + VideoColumns._ID + " DESC";

    Cursor cursor = null;
    try {
      cursor = resolver.query(query, projection, selection, null, order);
      // Log.e("testthum", "cursor number is " + cursor.getCount());
      // if (cursor == null)

      if (cursor != null && cursor.moveToFirst()) {
        // Log.e("testthum", "getLastVideoThumbnail: " +
        // cursor.getString(1));
        long id = cursor.getLong(0);
        Log.d("dyb", "return new media");
        return new Media(id, 0, cursor.getLong(2), ContentUris.withAppendedId(baseUri, id));
      }
      Log.d("dyb", "cursor is null");
    } finally {
      if (cursor != null) {
        cursor.close();
      }
    }
    Log.e("testthum", "return null");
    return null;
  }