0

I want to save data from internet in asset folder in Android. I used Eclipse IDE to develop the android application.

How i can achieve this ?

Thanks.

2 Answers2

5

The assets directory is readonly. It's defined and initialized at compile time, you cannot add or edit its contents.

Source (note it doesn't mention anything about writing to files...only reading them.)

Use the SDCard for such operations.

st0le
  • 33,375
  • 8
  • 89
  • 89
  • stole there is anyway to store video file with in applictaion other than sdcard – lucky android Dec 19 '11 at 06:15
  • @luckyandroid, If you want to keep your information private there are 2 methods 1) Private File 2) Private Database...Private files are stored on Phone Memory (which is very limited), i don't recommend saving videos there since their filesize will be huge...the same with the database, which will also include an overhead...So bottom line, stick with SDCard. – st0le Dec 19 '11 at 08:32
  • @stole i want to save video file with in application because i want to play also. If we save it into SD card then if we copy its apk file into another device then video will not play because it is stored in the previous device's SD card. – lucky android Dec 19 '11 at 09:19
  • @luckyandroid, that's a very strange usecase you have there...The only option you have is to store it on a server somewhere (with user credentials of course) – st0le Dec 19 '11 at 09:23
  • @stole do u know the how to play video from /data/data/package/ – lucky android Dec 19 '11 at 09:25
  • i mean my video is stored in /data/data/mypackage and i want to play this video – lucky android Dec 19 '11 at 09:26
  • [This Thread](http://stackoverflow.com/questions/3028717/how-to-play-videos-in-android-from-assets-folder-or-raw-folder) will help. Basically it states, that the contents of the assets folder is compressed (you could disable this apparently, i havent tried it though). So you can't directly play the file in the asset directory withou decompressing it. So your best bet is to store it in the `raw` folder and try to run it, if that doesnt work, copy the contents from the `raw` folder into the SDCard and then run it. – st0le Dec 19 '11 at 09:31
0

slote is right . use internal file storage/SD Card or sqLite database to save image

Shailendra Singh Rajawat
  • 8,172
  • 3
  • 35
  • 40