2

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);
Ankesh kumar Jaisansaria
  • 1,563
  • 4
  • 26
  • 44

1 Answers1

2

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);
chessdork
  • 1,999
  • 1
  • 19
  • 20
  • I get Array list of ids from user and then I want to display only those images. So how can I directly pass Arraylist in where clause? – Ankesh kumar Jaisansaria Jun 19 '16 at 16:26
  • this is not the safest way to do it as it can enable the user to directly input a SQL query which can lead to SQL injection Attempts. Whether you are taking input directly from user or hardcoding, it's always safe to use proper arguments to query the content provider. – Nitin Vats Jan 13 '21 at 09:35