After a long time and relentless try, the solution is here
1. You need to find the image id which is image unique id from images table in thumbnail table, query to thumbnail provider(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI) if you do not understand it, refer here , specifically IMAGE_ID,
Step 1 is to get reterievedImageId
.
reterievedImageId=Long.parseLong(cursor.getString(imageIdInImages));
2. Now using the reterievedImageId
get the image path, by again quering the content provider, only this time query the Images media provider(MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
String getImagePathFromThumbPath(String thumbPath)
{
String imagePath=null;
if(thumbPath!=null)
{
String[] columns_to_return ={MediaStore.Images.Thumbnails.IMAGE_ID};
String where =MediaStore.Images.Thumbnails.DATA+" LIKE ?";
long reterievedImageId=-1;
String valuesAre[]={"%"+thumbPath};
Cursor cursor = getContentResolver().query(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, columns_to_return, where, valuesAre, null);
if(cursor!=null)
{
int imageIdInImages=cursor.getColumnIndex(MediaStore.Images.Thumbnails.IMAGE_ID);
for (cursor.moveToFirst();!cursor.isAfterLast(); cursor.moveToNext())
{
//STEP 1 to retrieve image ID
reterievedImageId=Long.parseLong(cursor.getString(imageIdInImages));
}
if(reterievedImageId!=-1)
{
//STEP 2 Now
Log.i(TAG, "imageId-"+reterievedImageId);
String[] columnsReturn={MediaStore.Images.Media.DATA};
String whereimageId=MediaStore.Images.Media._ID+" LIKE ?";
String valuesIs[]={"%"+reterievedImageId};
Cursor mCursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columnsReturn, whereimageId, valuesIs, null);
int rawDataPath= mCursor.getColumnIndex(MediaStore.Images.Media.DATA);
for (mCursor.moveToFirst();!mCursor.isAfterLast(); mCursor.moveToNext())
{
imagePath=mCursor.getString(rawDataPath);
}
}
}
}
return imagePath;
}
If you still have doubt or error/exception, leave comment!
.
stackoverflow.comm
No comments:
Post a Comment