本文整理汇总了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;
}