0

I found that use SQLiteDatabase.createDatabase can create database to external storage, but use SQLiteOpenHelper can not create database to sdcard. Why?

Octavian Helm
  • 39,405
  • 19
  • 98
  • 102
Michael
  • 367
  • 5
  • 12
  • I vaguely recall (it was half a year ago) that I was not able to use SQLiteOpenHelper for SDCard, so I just switched to a default DB location (internal memory). The only reason of SDCard usage was DB size. Since my "records" have images I decided to store only image path in DB, while the images are on the SDCard. This allowed me to keep the DB size compact (internal memory is rather limited) and it works for so far. – Vit Khudenko Dec 07 '10 at 18:52
  • You have to have write access to the sdcard. If you have that, just supply a fully qualified path name to the database helper. – Howard Hodson Nov 28 '11 at 22:07
  • Or maybe not. I just checked my old code, and I have only processed databases I've downloaded to the sdcard. I don't use database helper in my database adapters for those. I just use SQLiteDatabase.openDatabase(databaseFile, null,SQLiteDatabase.OPEN_READONLY|SQLiteDatabase.NO_LOCALIZED_COLLATORS); – Howard Hodson Nov 28 '11 at 22:18

1 Answers1

2
> SQLiteOpenHelper can not create database to sdcard. Why? 

... because it gets the absolute filepath for the database from the context object.

DatabaseHelper(final Context context , String databaseName)

The default-Context implementation does not support user-paths.

You can provide your own context-implementation that provides a different file path as explained in my answer to stackoverflow sqliteopenhelper-problem-with-fully-qualified-db-path-name

Community
  • 1
  • 1
k3b
  • 14,517
  • 7
  • 53
  • 85