Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: path of assets folder for File()?

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.

like image 730
user1822613 Avatar asked Nov 14 '12 03:11

user1822613


People also ask

How do I access Assets files on Android?

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.

How do I find the 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.

How do I access an asset file?

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.


1 Answers

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]); 
    }
}
like image 110
Jeremy Lyman Avatar answered Sep 21 '22 08:09

Jeremy Lyman