Android - Java - MediaStore - How to use selection for multiple conditions -


i wan't document (docs) files android device. use contentresolver mediastore.files achive that. can files 1 type , example: pdf , wonder how files number of types.

my code:

    string selection = mediastore.files.filecolumns.mime_type + "=?" +             "";     string[] selectionargs = new string[] { mimetypemap.getsingleton().getmimetypefromextension("pdf")};      arraylist<myfile> list  = new arraylist<myfile>();      uri contenturi  = mediastore.files.getcontenturi("external");       string[] columns = {             mediastore.files.filecolumns.mime_type ,             mediastore.files.filecolumns.media_type ,             mediastore.files.filecolumns.data ,     };     string sortorder = null;       cursor cursor = contentr.query(contenturi ,             columns ,             selection ,             selectionargs ,             sortorder); 

how can use selection & selectioargs multiple conditions in sql: or , , ... selectionargs have files types i'm looking for: pdf , txt , doc ...

for example: selection = mediastore.files.filecolumns.mime_type + "=?" + "or" + mediastore.files.filecolumns.mime_type + "=?" ;

selectionargs = {"pdf" , "txt"};

thanks or direction :-)

you need add more selectionargs, each every file type. or create list or array contains file types strings. next need loop goes next file type until there no more left. example:

arraylist<myfile> list  = new arraylist<myfile>(); arraylist<string> filetypearray = new arraylist<dstring>();   for(int = 0; < filetypearray.size(); i++){      string selection = mediastore.files.filecolumns.mime_type + "=?" + "";      string[] selectionargs = new string[] {     mimetypemap.getsingleton().getmimetypefromextension(filetypearray.get(i))};      uri contenturi  = mediastore.files.getcontenturi("external");     string[] columns = {             mediastore.files.filecolumns.mime_type ,             mediastore.files.filecolumns.media_type ,             mediastore.files.filecolumns.data ,     };     string sortorder = null;       cursor cursor = contentr.query(contenturi ,             columns ,             selection ,             selectionargs ,             sortorder); } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

ios - MKMapView fails to load tiles with HTTP 410 error -

c# - How to utilize EF and LINQ to add filters and specify tables, columns, filters and order by dynamically -