In our project we need to store databases to an external SD-card instead of the default path. To do this we have a custom class that inherits from ContextWrapper
and overrides openOrCreateDatabase
:
@Override
public SQLiteDatabase openOrCreateDatabase(String name,
int mode,
SQLiteDatabase.CursorFactory factory) {
...
}
In API level 11 a new version of openOrCreateDatabase
was added that adds a parameter of type DatabaseErrorHandler
. On ICS it seems like it's this version that is called. I have verified this using:
@Override
public SQLiteDatabase openOrCreateDatabase(String name,
int mode,
SQLiteDatabase.CursorFactory factory,
DatabaseErrorHandler errorHandler) {
return openOrCreateDatabase(name, mode, factory);
}
The problem is that I cannot add this function to the code because DatabaseErrorHandler
was added in API level 11 and I need to have backwards compatibility with at least API level 8.
So how to I solve this issue?
AFAIK, as of Android 2.2, SQLiteOpenHelper
supports databases on external storage, by supplying a full path to the database file.
That being said, bear in mind that external storage and internal storage sorta merged with Android 3.0. In Android 1.x and 2.x, internal and external storage were separate partitions with separate space. In Android 3.0+, they share a partition, with external storage simply being a designated directory in the partition used by internal storage.
Hence, if the reason you are using external storage is due to size considerations, that will no longer be needed starting with API Level 11. If you are using external storage specifically because the user has access to it, that would still be relevant, though I've always been nervous about that, and am more nervous now because Android 3.0 now allows simultaneous access to external storage by apps and the user.