I want to add my one file (example mp3) inside an apk so that when user start that application for the first time it should copy that file into phone memory.
Can someone give me some suggestions regarding how to do this?
Try putting the mp3 file in the assets/ folder. if your project doesn`t have one, create one on the same level as your res/ folder. Then, when the app runs, save the file to the sd card.
Have try to put your file into raw or asset folders.because when AAPT packaging for .apk with .class then its focuse goes to res folders and then at last to manifest file...so when you puts your file into these folders then these files takes their space into .apk.
And use a variable to know your Application is installed for very first time then make folders(where you want) to copy that file...
Related
I am using the below code to create a file in android as
File file = new File(getApplicationContext().getFilesDir(), "content.txt");
I want to open the file in my phone. I went to the path
Local storage/Android/data/<my package>/files/
However, I cannot see the file. My Android version is 5.0.1. What is happen? One more thing, Do you think the above way is a good way to save file? What is common path to save a file in Android? Thanks
The file locates in /data/data/[your package]/files,it's app private directory.
It's a good way or not depends on the purpose of your file.
if you want your file visable only to you(the app developer),the folder is right
if the file can be visable to others and the file is large,then you can put it to sdcard folder
if you want the file stay even if your app being removed,you shouldn't put it in this folder.Because when an app removed,the all data in /data/data/[package name]/ will be deleted also.
You find in:
/data/data/[your package name]/files/
I am planning my android app with some files in the app folder, but i didn't figure out how to add files to my project. I don't want to use the files as resources because the user should be able to save or download more files in the same folder and i just wanted to add the basic set of files.
Can anyone help me? :/
I don't want to use the files as resources because the user should be able to save or download more files in the same folder and i just wanted to add the basic set of files.
There is no direct means of doing this. If you package your files as assets (in assets/) or as raw resources, you are welcome to copy them out of your APK into internal storage on first run of your app.
I have an application with a lot of data resources in the res-drawable folder, is it possible to put the res folder in expansion file or i need to make changes in the code? i tried to read about this in the expansion files documantation but cant figure it out.
is it possible to put the res folder in expansion file
No, sorry.
i need to make changes in the code
Yes.
I need to place a raw *.txt file in my android-project to read from it and output general terms and conditions in a dialog.
However, Eclipse shows, that my .txt file contains errors (see title). It's not an xml file and should be treated like a raw file. Why the error?!?! How can i fix it?
Thanks in advance.
Solved:
Eclipse restarting does NOT help.
Creating a file with the eclipse 'New File'-Wizard on the raw folder helps. It's kind of a bug.
DONT: Create a file in another folder and put it in the res/raw folder afterwards. Eclipse doesn't recognize the file has been move to a folder where problems should be ignored. Alittle buggy tho.
It sounds like it is interpreting it as an XML file; is it in res/raw or assets/ ? Non-xml resources should be put in one of those two project directories.
I am trying to load an xml file located in the /assets folder of an android project by name using this method:
getAssets().openXmlResourceParser("thefilename.xml");
However, executing this code always throws a "FileNotFound" exception, even though the file is located in the /assets folder and is with the correct file name.
Now, I have not put the file in the /res/xml folder because I really need to be able to 1. edit the file right on the device itself and most importantly 2. add new xml files to the application without issuing an update, to allow for easy user modifications.
Thanks in advance.
I think what you are looking for is either getAssets().open("thefilename.xml") or getAssets().openFd("thefilename.xml") depending on what the end use of the file is. You can see from Dianne's response in this post awhile back that openXmlResourceParser() is not really usable just to gain access to files in the assets/ directory: http://goo.gl/2KfgT
From there you will have a stream that you could feed into a SAXParser or do whatever else you choose.
Side Note: On the points you mentioned you really can't edit files directly in assets/ or add new files to assets/ at runtime. You will need to work with files on either internal or external storage to do those things. You probably already knew that, but I thought I'd mention it.
Hope that Helps!