Android, how do can I get a list of all files in a folder? -
i need name (string) of files in res/raw/
i tried:
file f = new file("/"); string[] somefiles = f.list();
it looks root directory root of android emulator...and not computers root directory. makes enough sense, doesn't me find out raw folder exists.
thanks!
update: great replies. appears of these working, getting me half way. perhaps more detailed description aid...
i want mp3 files in raw folder can names, add them uri play random mp3 in following way...
string uristr = "android.resource://"+ "com.example.phone"+ "/" + "raw/dennis"; uri uri = uri.parse(uristr); singletonmediaplayer = mediaplayer.create(c, uri);
when put "dennis.mp3" assets folder, show expected...however, using above code, can't access mp3 anymore...unless there along line of:
string uristr = "android.assets://"+ "com.example.phone"+ "/" + "dennis"; uri uri = uri.parse(uristr);
thanks again helpful answers far.
to list names of raw assets, filenames extensions stripped off, can this:
public void listraw(){ field[] fields=r.raw.class.getfields(); for(int count=0; count < fields.length; count++){ log.i("raw asset: ", fields[count].getname()); } }
since actual files aren't sitting on filesystem once they're on phone, name irrelevant, , you'll need refer them integer assigned resource name. in above example, integer thus:
int resourceid=fields[count].getint(fields[count]);
this same int you'd referring r.raw.whateveryounamedtheresource
Comments
Post a Comment