Android: path of assets folder for File()?
15,450
Assets and resources are accessible using file:///android_asset and file:///android_res.
But in this case you will want to do something like this :
Resources res = getResources()
AssetManager am = res.getAssets();
String fileList[] = am.list(dirFrom);
if (fileList != null) {
for ( int i = 0;i<fileList.length;i++) {
Log.d("",fileList[i]);
}
}
Author by
user1822613
Updated on July 20, 2022Comments
-
user1822613 almost 2 years
I have some files in the assets folder of my project, and I want to list them, so I put this in my code:
File dir = new File("com.packagename/assets/fonts"); File[] fileList = dir.listFiles();
Which path should I put to make it work? I want it so users could install new fonts (I don`t know how to do this yet) so I need to list all the fonts in the folder, including post-installed fonts. If there is any other solutions, please share.
-
user1822613 over 11 yearsare you sure the resources part is required?? i did something similar without it and it worked
-
Jeremy Lyman almost 11 yearsIt's a directory string such as "images" where you're searching for your assets.