Ankesh kumar Jaisansaria Ankesh kumar Jaisansaria - 1 year ago 105
Android Question

Android Content Provider Query with multiple WHERE selection

I am using androids content provider Media.Store External Image to fetch image file path.

I want to get file path of only those images who's _ID equals to either of :-
122234, 33245, 66782, 55782.

So how do I frame my Cursor.query to achieve this.

My existing code:-

Uri uri;
Cursor cursor;
int column_index_data ;
uri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;

String order = MediaStore.MediaColumns.DATE_ADDED + " "+ "desc";
String[] projection = { MediaStore.MediaColumns.DATA};

cursor = getContentResolver().query(uri, projection, null,
null, order);

column_index_data = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);


You should be able to write the WHERE clause directly. For example:

Cursor c = getContentResolver().query(uri, projection, "_id IN (1, 2, 3, 4)", null, order);