I need to get Absolute path to Folder in Assets. Some like this for sd-card:
final String sdDir = Environment.getExternalStorageDirectory() + "Files";
What i do incorrect?
First I try to get path (in green ractangle) this way but I alwase get "False". Then I comment this block and try to get path from getAssets().list(); But I get 3 folders witch I see first time.
I want to make massive like this "green" but I need to use files from assets:
Look the image
Help me to get absolute path to my Files folder.
android.content.res.AssetManager. Provides access to an application's raw asset files; see Resources for the way most applications will want to retrieve their resource data.
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.
android.content.res.AssetFileDescriptor. File descriptor of an entry in the AssetManager. This provides your own opened FileDescriptor that can be used to read the data, as well as the offset and length of that entry's data in the file.
In Android Studio, click on the app folder, then the src folder, and then the main folder. Inside the main folder you can add the assets folder.
I'm not exactly sure what you're trying to do, so I'll try to cover the bases, and maybe this will help.
If you are just trying to get a list of what's in your assets, then use getAssets().list("Files")
. (You have to use the subdirectory, because of this).
If you are trying to get an absolute path to your assets directory (or any subdirectory), you can't. Whatever is in the assets directory is in the APK. It's not in external storage like on an SD card.
If you are trying to open up files in the assets directory, use AssetManager.open(filename)
to get the InputStream
. Here, filename should be the relative path from the assets directory.
EDIT
I'm not sure what you mean by "massive", but if you want to load the file black.png
from assets instead of the SD card, then write this:
// must be called from Activity method, such as onCreate() AssetManager assetMgr = this.getAssets(); mColors = new Bitmap[] { BitmapFactory.decodeStream(assetMgr.open("black.png")); // and the rest };
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