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.
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. Step 3 – Right click app >> New >> Folder >> Assets folder.
Step 2: Go to the app > right-click > New > Folder > Asset Folder and create the asset folder. Step 3: Android Studio will open a dialog box.
To view asset files in Files home, select Libraries and then select Asset Library . To view and edit asset files in Setup, enter Asset Files in the Quick Find box, then select Asset Files.
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]);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With