3

Is there a way to directly access the sqlite database from the assets folder, or is it always necessary to first copy this db to the device data directory, in the app's database folder?

(Example - Environment.getDataDirectory()+"/data/com.example.myapp/databases/myDb.db")

I ask because I have a db that is quite large (about 11MB) and has to be shipped with the app. After the database has been copied to the data directory, the app will take twice the space. I want to avoid this.

Also, is it possible to delete the contents of the asset folder after the app has been installed? This would help save some space.

Thanks

Mukul Jain
  • 1,807
  • 9
  • 26
  • 38

2 Answers2

0

assets folder is a compile time folder. You cannot access without copying in your linux

Sarmad
  • 389
  • 2
  • 8
0

yes you can delete the files from the database from the assets folder : you can use "android.resource://"+getPackageName() + "/" to access the folder and then use

File f=new File(_pathToAssestFolder,databasename);
        if(f.exists())
        {f.delete();
        }

but do it in the last line of onCreate() function;

try it

Rob Keniger
  • 45,830
  • 6
  • 101
  • 134
  • as far as I understand the APK is a signed zip file that cannot be modified. Take a look at: http://stackoverflow.com/questions/4398523/how-we-can-remove-a-file-from-the-assets-folder-at-runtime-in-android – Sergio Jan 18 '12 at 15:06