I am a novice programmer,and encounter a problem in the development of an Android application.I have a subfolder raw under the folder res, now ,i want to traverse the folder raw and get files' name and path in the folder. who can help me?
There are some MP3 files in the raw folder ,and i want to list of their name and get their path for use VideoView to play it. poor English, forgive meļ¼thanks!
If you want to be able to get a list of files shipped with the app, move the files in the assets folder.
For example : if you create a folder in the assets folder called 'video' then you can retrieve a string array with the filenames like this :
String[] filesInAssets = getResources().getAssets().list("video");
I don't see a solution for reading the files under the res folder.
Related
I am writing a simple Android Sudoku app, during the first stage, I want to store some Sudoku puzzle in a file and then get them. The file is a simple xml file, it's format just like:
<puzzle>23000...31</puzzle>
<puzzle>45013...67</puzzle>
There are 9 * 9 character in "puzzle" tag.
My question is, what's the correct directory for the file, and how to get the data from it?
You can store your file in assets directory or even raw directory. Honestly, I would advise you to use the first solution: you will then be able to use inside your code:
getAssets().open(fileName)
"assets" directory has to be at the root of your project (same level as ""src", "res", "libs"...
"raw" directory has to be inside the "res" one.
I read a tutorial on how to get names of files in an absolute path, but now I want to get all files - for example in my internal storage-
I mean by all the files, the files which are in the folders not only in an absolute path.
for example if my internal have folders and files like that
/music
/videos
/data
mine.png
mohamed.txt
and my music folder have files like
him.png
sir.doc
I want a list like that
mine.png
mohamed.txt
him.png
sir.docx
I hope some one got me.
Thanks
Suppose I store various images in raw folder. However, my own code first learns of the file names at runtime. (It reads a text configuration file at startup.) Is it possible to then search "raw" folder in my android app and if found, load image from raw into imageview?
Okay, thanks to Mario I got on track to doing some research. These 5 SO's explain everything:
Android images in /assets or res/raw
Reading assets or raw or resource files as a File object in Android
How to reference a File in raw folder in Android
Check for file existence in androids assets folder?
Difference between /res and /assets directories
can i create folders, besides raw folder, for storing different kind of files?
For examples, my application need to count all the images put in a folder.
So, I need a specific folder for images only, and other folders for sounds, for .txt etc!
But when i tried to create a new folder, I couldn't reach it :(
It is just a hunch, but you might have more luck using the assets folder instead. You can certainly use it to store embedded web sites which have subfolders.
In general you cant create custom resource folders. But you can use assets dir and place your resources there. You can make as much subfolders in assets dir as you need. But android won't help you to manage your files in assets dir. Read this.
Im new with android and JAVA but im trying a simple app. Its a player that has its own mp3 files. So I put them all in the assets folder. I can play them without any problem. What I cant do is to read the meta-data, or tag information of the file such as Title, album, etc...
Is it possible to get tag information from files on assets or raw folder?
Thanks!
They are just raw files in your .apk. You will need to use some code that parses the tag data out of an .mp3, and point it at that data in your .apk.