ehrid
ehrid

Reputation: 125

Android assets folder is empty

I want to list folders and files in asset folder, but I find out i empty. I searched for the answer but it did not helped, on google, stackoverflow and many others.

I tried many approaches with AssetManager and only that gave some output was:

getAssets().list("/");

But assets folder it listed was empty...

I run application from eclipse (device on usb). Can anyone tell me what I do wrong? I have feeling that assets folder I open is not form my application...

Thanks in advance!

Upvotes: 5

Views: 2748

Answers (4)

CaptainCrunch
CaptainCrunch

Reputation: 1403

I see you were using Eclipse, I switched to Android Studio but had the same problem. Comparing many answers led me to this:

https://stackoverflow.com/a/33542563/524355

The asset folder is "next" to the res folder (in AS, there is even a wizard for it). I put it manually "into" the res folder that's why asset folder was gone/not compiled into the apk! If this is done by the build tools that you use in Eclipse (ADT) you might have suffered from the same situation.

assets not inside but parallel to res folder

Upvotes: 0

focs
focs

Reputation: 182

I was using getAssets().list("/"); and it returned a list of the files in the root of the app:

D/        (25498): Listing files in /
D/        (25498): AndroidManifest.xml
D/        (25498): META-INF
D/        (25498): assets
D/        (25498): classes.dex
D/        (25498): lib
D/        (25498): res
D/        (25498): resources.arsc

Then I tried listing "/assets" but it was always empty. Then I found out that a relative path is needed and / for the root folder can not be used.

getAssets().list(""); lists the files in the root of the assets folder.

Upvotes: 5

113408
113408

Reputation: 3444

You can get the assets files like this:

try {
    Resources res = getResources();
    AssetManager am = res.getAssets();
    String fileList[] = am.list("/");
} catch (IOException e) {
    e.printStackTrace();
}

Upvotes: 0

Wagner Michael
Wagner Michael

Reputation: 2192

Try this:

AssetManager assetManager = appContext.getAssets();
String[] filelist = assetManager.list("");

Upvotes: 0

Related Questions