android - Read file from "extsdcard" -


i have music in both sdcard , extsdcard

i use cursor list them:

uri devicemusic = mediastore.audio.media.external_content_uri; string selection = mediastore.audio.media.is_music + " != 0"; string sortorder = mediastore.audio.media.display_name; cursor cursor = this.getcontentresolver().query(devicemusic, null,             selection, null, sortorder);  if (cursor == null || cursor.isclosed()) {         return;     }  // music information if (cursor.movetofirst()) {        // file path        string data = cursor.getstring(cursor                     .getcolumnindex(mediastore.audio.media.data)); } while (cursor.movetonext()); 

then use code below judge type of music:

public static string getfileheader(string filepath) {     fileinputstream = null;     string value = null;     try {         = new fileinputstream(filepath);         byte[] b = new byte[3];         is.read(b, 0, b.length);         value = bytestohexstring(b);     } catch (exception e) {         e.printstacktrace();     } {         if (null != is) {             try {                 is.close();             } catch (ioexception e) {             }         }     }     return value; } 

this method works fine on sdcard,

but encounter "filenotfoundexception" on extsdcard

so try check file hard code:

file file = new file(             "/storage/extsdcard/(i can't help) falling in love - ub 40.mp3");      if (file.exists()) {         log.i("", "");     } 

it returns false when above code in loop of

while (cursor.movetonext()) 

but when hard code in other place such oncreate

it return true...

what's situation?


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -