本文整理匯總了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();
}
}
示例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;
}
示例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;
}
示例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();
}
}
示例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();
}
}
示例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;
}
示例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;
}