Click here to Skip to main content
15,879,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating an app and use Ratio.xml as database. I added this file manually in external storage in a folder and my app is working.

I want to include this file in my apk package and install this file in any of the folder in the device and not in external storage . I added this file in asset folder but it is read only, I can't modify and save in this file. Please tell me where to put this file in my project and create package.
Posted

I would keep the "original" version of your Ratio.xml in the asset folder, and on start-up of the app I would copy it to the Internal Storage by reading the contents of Ratio.xml and writing it to a new file using Context.openFileOutput. Obviously only overwrite the copy if it's not already there.

Calling Context.openFileOutput will return a FileOutputStream so using that it's pretty much standard Java to read and write the file. The file will be private to you application. I think using the Internal Storage[^] is the best solution here, but there are other ways[^] for you to achieve the same, but in different ways.

Hope this helps,
Fredrik
 
Share this answer
 
Comments
Baburc 3-Sep-14 12:13pm    
I want to include this file in my apk package creation, Please tell me where to put this file in solution explorer or add this file during setup in the device storage.
Fredrik Bornander 4-Sep-14 3:21am    
Store is as an Asset in the project.
And I don't think it cab be added as a writable file to the storage during setup, that's something you'd have to implement yourself and have your application do on startup.
See https://www.youtube.com/watch?v=A-cIZoSa5bA[^], it's for an SQLite database, but the principle is the same.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900