I am looking to add additional content to my app as extra databases. Should I put them in apks and content providers, so they can be updated from google play directly, or just as new db files downloaded straight into the app.
My problem with the content-provider/apk method, is they all have to be declared in the android manifest, and I might have multiple databases even hundreds, so would need 100s of content-provider declarations in my manifest, even when the user may have only a couple or even none of them.
Unless there is a way I can generate the manifest dynamically? Or load the content-providers outside of the manifest?
Thanks
I think the cleanest way to do this is to have one unique ContentProvider for all your db files.
You should build your URI's around database selection.
For example : content://com.your.package/a_db_file/something/things/5
Then when implementing your ContentProvider, parse the Uri to get the a_db_file segment, open the corresponding db file, then do the needed work according to the rest of the segments.
Maybe you will need a method like getCorrectDb(String a_db_file).
Inside this method you should make the correct call to a sqlLiteOpenHelper that properly match the needed db file.
Also take a look at UriMatcher, it might be useful for you. :)
In the end you should have something like:
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
// TODO : Parse uri to get a_db_file string.
SQLiteDatabase database = getCorrectDb(a_db_file);
// TODO : get cursor from db according to other segments of uri.
return cursor.
}
I'd use one content provider to keep things simple and utilize the "attach database" sql command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With