9

After searching 1 hour i do not found any solution to my problem.

I want to move a file from sdcard to assets folder and also overwrite the existing file in assets folder (both file are sqlite database have same name with just a little difference in data )

??

Sunny
  • 14,522
  • 15
  • 84
  • 129

3 Answers3

13

Actually, The behaviour of the android .apk file is read only so the directory structure which are in that apk file follows the same, So no one can write this files or make changes on that at runtime,that's why You can't make a changes in /asset folder at runtime. you can read file from it (means copy files which are available in asset to any internal storage or /sdcard but not write it to vice-versa)

Its apply on all the directories which are build in .apk files. As per docs.

user370305
  • 108,599
  • 23
  • 164
  • 151
  • sorry same comment but i need solution :) I have database in assets folder and also on server now i want to change the database later on server so that user can get latest update.how can i do this? How will user get that database? – john smith 7 secs ago – Sunny Dec 06 '11 at 12:12
  • You have to write that database to either internal storage or in sdcard, (Internal storage is preferable).. – user370305 Dec 06 '11 at 12:13
  • can you guide me how to do this? – Sunny Dec 06 '11 at 12:15
  • if i write database in sdcard or in internal memory how to copy that database in my app database? – Sunny Dec 06 '11 at 12:17
  • 1
    Ok, just simple put your created database in asset directory, then when your application first time installed copy that database file in internal storage /data/data/packagename/databases/ and then open that database file to your application stuff, now when you get update from web server just update data to database file which are place on internal storage of above path.. – user370305 Dec 06 '11 at 12:18
  • Just look at some tutorial of database you can understand clearly, If you want any more help from me then ask at any time.. – user370305 Dec 06 '11 at 12:23
4

Assets folder are not Writable it is only readable so you cant copy from sdcard to assets, yes you can copy from assets to sdcard

Nikunj Patel
  • 21,853
  • 23
  • 89
  • 133
  • i know that http://stackoverflow.com/questions/4447477/android-how-to-copy-files-in-assets-to-sdcard but my problem is different. – Sunny Dec 06 '11 at 12:01
  • +1 for information that assets folder is not writable i will keep that in my mind :P – Sunny Dec 06 '11 at 12:25
1

If you want other apps not to access your database then what you can do is

  1. Download the database from website. create a temp database also in app directory.
  2. getDatabasePath() this will give you the path of the dummy database you have created now replace this with the one you downloaded.

PS.: User and apps having root access still able to access it and you cant do anything in that scenario

ingsaurabh
  • 15,249
  • 7
  • 52
  • 81