Can I download an SQLite db on /sdcard and access it from my Android app? Can I download an SQLite db on /sdcard and access it from my Android app? android android

Can I download an SQLite db on /sdcard and access it from my Android app?


Sure you can. The docs are a little conflicting about this as they also say that no limitations are imposed. I think they should say that relative paths are to the above location and dbs there ARE private. Here is the code you want:

File dbfile = new File("/sdcard/mydb.sqlite" ); SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbfile, null);System.out.println("Its open? "  + db.isOpen());


Try this:

String dir = Environment.getExternalStorageDirectory().getPath()File dbfile = new File(dir+"/mydb.sqlite"); SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbfile, null);System.out.println("Its open? "  + db.isOpen());


Just an idea:

  • you can put your database.db into the assets folder.

  • if your database.db file is larger than 2Mb the system is unable to compress it, so you need other one options

  • you can rename your database.db for example database.jit or database.mp3 - which are not compressed, than at the first run you can rename it to database.db