Android refuses to read files -
i trying load mp3 files array, android keeps showing error : java.lang.nullpointerexception: attempt length of null array
, error in line : if(path.isdirectory() && path.listfiles().length > 0)
i added these 2 permission lines manifest files, there no effect :
<uses-permission android:name="android.permission.read_external_storage"/> <uses-permission android:name="android.permission.write_external_storage"/>
my function called : locatesongs(environment.getexternalstoragedirectory());
and function iterate full device :
private void locatesongs(file path) { if(path.isdirectory() && path.listfiles().length > 0){ file files[] = path.listfiles(); for(file f : files){ locatesongs(f.getabsolutefile()); } }else if(path.isfile() && path.getname().contains(".mp3")){ // // todo: 2/5/2016 add more types other mp3 mediametadataretriever metaretriver = new mediametadataretriever(); metaretriver.setdatasource(path.getabsolutepath()); song newsong = new song(); newsong.setalbum(metaretriver.extractmetadata(mediametadataretriever.metadata_key_album)); newsong.setartist(metaretriver.extractmetadata(mediametadataretriever.metadata_key_artist)); newsong.setauthor(metaretriver.extractmetadata(mediametadataretriever.metadata_key_author)); newsong.setname(metaretriver.extractmetadata(mediametadataretriever.metadata_key_title)); newsong.setbitrate(metaretriver.extractmetadata(mediametadataretriever.metadata_key_bitrate)); newsong.setgenre(metaretriver.extractmetadata(mediametadataretriever.metadata_key_genre)); newsong.setdatasourse(path.getabsolutepath()); newsong.setduration(metaretriver.extractmetadata(mediametadataretriever.metadata_key_duration)); byte[] art = metaretriver.getembeddedpicture(); bitmap songimage = bitmapfactory.decodebytearray(art, 0, art.length); newsong.setimage(songimage); } }
thanks tried help, i've found solution, problem due using android 6.0 (marshmallow) emulator, problem solved here : http://developer.android.com/training/permissions/requesting.html
Comments
Post a Comment