Use MediaStore.Images and Cursor to query local images and image thumbnails

Let's look at an example first:

String[] projection = { MediaStore.Images.Thumbnails._ID ,MediaStore.Images.Thumbnails.DATA};
Cursor cursor = mActivity.getContentResolver().query(
    MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,//Uri of specified thumbnail database

    projection,//Specify the field to be queried
    MediaStore.Images.Thumbnails._ID + " = ?",//Query condition
    new String[] {"123" }, //The value corresponding to the question mark in the query condition

    null);
cursor.moveToFirst();
String id = cursor.getString(0);

String data = cursor.getString(1);

 

Query the image thumbnail database to obtain the thumbnail information whose id is equal to 123.

Converted to Sql statement is select MediaStore.Images.Thumbnails._ID , MediaStore.Images.Thumbnails.DATA from MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI where MediaStore.Images.Thumbnails._ID = 123

 

If you want to query images, the Uri address is: MediaStore.Images.Media.EXTERNAL_CONTENT_URI

 

When getting thumbnails: Bitmap bitmap = MediaStore.Images.Thumbnails.getThumbnail (mActivity.getContentResolver(), id, Thumbnails.MICRO_KIND, null)

MediaStore.Images.Media.BUCKET_ID, // Contains the folder ID of the image file directly to prevent the same folder name under different

MediaStore.Images.Media.BUCKET_DISPLAY_NAME, // The folder name that directly contains the image file
MediaStore.Images.Media.DISPLAY_NAME, // The image file name
MediaStore.Images.Media.DATA, // The absolute path of the image

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326856349&siteId=291194637