當前位置: 首頁>>代碼示例>>Java>>正文


Java Media.query方法代碼示例

本文整理匯總了Java中android.provider.MediaStore.Images.Media.query方法的典型用法代碼示例。如果您正苦於以下問題:Java Media.query方法的具體用法?Java Media.query怎麽用?Java Media.query使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.provider.MediaStore.Images.Media的用法示例。


在下文中一共展示了Media.query方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getRealPathByUri

import android.provider.MediaStore.Images.Media; //導入方法依賴的package包/類
public static String getRealPathByUri(Context context, Uri uri) {
    if ("file".equals(uri.getScheme())) {
        return uri.getPath();
    }
    try {
        Cursor cursor = Media.query(context.getContentResolver(), uri, new String[]{"_data"});
        String realPath = null;
        if (cursor == null) {
            return null;
        }
        int columnIndex = cursor.getColumnIndexOrThrow("_data");
        if (cursor.getCount() > 0 && cursor.moveToFirst()) {
            realPath = cursor.getString(columnIndex);
        }
        cursor.close();
        return realPath;
    } catch (Exception e) {
        return uri.getPath();
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:21,代碼來源:MQUtils.java

示例2: getBuckets

import android.provider.MediaStore.Images.Media; //導入方法依賴的package包/類
static List<Image> getBuckets(Context context) {
    final Cursor cursor = Media.query(context.getContentResolver(), URI, PROJECTION,
            "1 = 1) GROUP BY (" + Media.BUCKET_ID,  // WTF
            Media.DATE_ADDED + " DESC");

    final List<Image> images = new ArrayList<>();
    final File root = Environment.getExternalStorageDirectory();

    if (cursor.moveToFirst()) {
        do {
            final Image image = Image.fromCursor(cursor);
            if (image.getParentFile().equals(root)) {
                continue;
            }
            images.add(image);
        } while (cursor.moveToNext());
    }

    cursor.close();

    return images;
}
 
開發者ID:oxoooo,項目名稱:nomedia,代碼行數:23,代碼來源:MediaStoreUtils.java

示例3: getImages

import android.provider.MediaStore.Images.Media; //導入方法依賴的package包/類
static List<Image> getImages(Context context, String bucketId, int limit) {
    final Cursor cursor = Media.query(context.getContentResolver(), URI, PROJECTION,
            Media.BUCKET_ID + " = ?", new String[]{bucketId},
            Media.DATE_ADDED + " DESC");

    final List<Image> images = new ArrayList<>();
    int count = 0;

    if (cursor.moveToFirst()) {
        do {
            images.add(Image.fromCursor(cursor));
            count++;
        } while (count < limit && cursor.moveToNext());
    }

    cursor.close();

    return images;
}
 
開發者ID:oxoooo,項目名稱:nomedia,代碼行數:20,代碼來源:MediaStoreUtils.java

示例4: getBucketIds

import android.provider.MediaStore.Images.Media; //導入方法依賴的package包/類
public HashMap<String, String> getBucketIds() {
    Uri uri = mBaseUri.buildUpon()
            .appendQueryParameter("distinct", "true").build();
    Cursor cursor = Media.query(
            mContentResolver, uri,
            new String[] {
                Media.BUCKET_DISPLAY_NAME,
                Media.BUCKET_ID},
            whereClause(), whereClauseArgs(), null);
    try {
        HashMap<String, String> hash = new HashMap<String, String>();
        while (cursor.moveToNext()) {
            hash.put(cursor.getString(1), cursor.getString(0));
        }
        return hash;
    } finally {
        cursor.close();
    }
}
 
開發者ID:petalyaa,項目名稱:Launchpet2,代碼行數:20,代碼來源:ImageList.java

示例5: getBucketIds

import android.provider.MediaStore.Images.Media; //導入方法依賴的package包/類
public HashMap<String, String> getBucketIds() {
    Uri uri = mBaseUri.buildUpon().appendQueryParameter("distinct", "true").build();
    Cursor cursor = Media.query(mContentResolver, uri, new String[]{Media.BUCKET_DISPLAY_NAME, Media.BUCKET_ID}, whereClause(), whereClauseArgs(), null);
    try {
        HashMap<String, String> hash = new HashMap<String, String>();
        while (cursor.moveToNext()) {
            hash.put(cursor.getString(1), cursor.getString(0));
        }
        return hash;
    } finally {
        cursor.close();
    }
}
 
開發者ID:goodev,項目名稱:droidddle,代碼行數:14,代碼來源:ImageList.java

示例6: createCursor

import android.provider.MediaStore.Images.Media; //導入方法依賴的package包/類
@Override
protected Cursor createCursor() {
    Cursor c = Media.query(
            mContentResolver, mBaseUri, IMAGE_PROJECTION,
            whereClause(), whereClauseArgs(), sortOrder());
    return c;
}
 
開發者ID:petalyaa,項目名稱:Launchpet2,代碼行數:8,代碼來源:ImageList.java

示例7: createCursor

import android.provider.MediaStore.Images.Media; //導入方法依賴的package包/類
@Override
protected Cursor createCursor() {
    Cursor c = Media.query(mContentResolver, mBaseUri, IMAGE_PROJECTION, whereClause(), whereClauseArgs(), sortOrder());
    return c;
}
 
開發者ID:goodev,項目名稱:droidddle,代碼行數:6,代碼來源:ImageList.java


注:本文中的android.provider.MediaStore.Images.Media.query方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。