Intimidation of assets

I am completely confused. There is an "assets" folder in my project, but AssetManager does not reference this folder. Therefore, I have three questions:

First, where is the folder referenced by AssetManager?

Secondly, how can I put files in this folder?

Thirdly, how do I access the files that I put in the assets folder of my project? (Consolidated question: what is the purpose of this folder if it is not used by AssetManager?)

Documents cannot fully clarify these issues. Very frustrating.

+1
source share
4 answers

You can drag the necessary resources in your project to the / assets folder and access them through the code:

context.getAssets().open(YOUR_FILE_NAME); 

context.getAssets() will simply return an AssetManager instance for your application package, from where you can access the files.

Hope this helps!

0
source

There is an "assets" folder in my project, but AssetManager does not reference this folder.

Yes it is.

First, where is the folder referenced by AssetManager?

assets/ in your project.

Secondly, how can I put files in this folder?

It depends on your operating system. Most operating systems have β€œfile managers” that support some kind of drag and drop mechanism for copying files. If you use Eclipse, drag and drop to Eclipse or be sure to press F5 to update Eclipse for changes made to your Eclipse project outside of Eclipse.

Thirdly, how do I access the files that I put in the assets folder of my project?

Using AssetManager or sometimes via file://android_asset/ Uri values ​​(and note that this is android_asset , especially when the assets/ project directory, the plural is very annoying).

So, if I understand you correctly, I should not do: AssetManager mgr = getAssets ();, which gives me completely different contents of the folder.

No, just tried it. I still get the wrong contents of the folder, i.e. Not the folder of my project resource.

Then your project is seriously damaged. Many, many developers work perfectly.

For instance:

+1
source

If you have the file resources of the /foo.bar project, then during run getAssets().open("foo.bar") this file will open.

0
source

Using Android Studio , I had the same issue.

I tried putting my "assets" folder in "res", as it was when we used Eclipse.

But now it has moved to " src / main / assets ". Here you should put your files.

See accepted answer: assets-folder-in-android-studio

0
source

All Articles