Friday, June 29, 2012

Re: [android-developers] Is there any way of providing a prebuilt database within an app?

Or you could do it in pedestrian mode and extend SQLiteOpenHelper yourself.

public void createDataBase() throws IOException {
    boolean dbExist = checkDataBase();
    if (dbExist) {
        // do nothing - database already exist
    } else {
        // By calling this method and empty database will be created into
        // the default system path
        // of your application so we are gonna be able to overwrite that
        // database with our database.
        this.getReadableDatabase();
        try {
        copyDataBase();
        } catch (IOException e) {
        throw new Error("Error copying database");
        }
    }
    }

On Friday, June 29, 2012 6:38:58 AM UTC-4, Mark Murphy (a Commons Guy) wrote:
On Fri, Jun 22, 2012 at 7:46 AM, Neil <neil.capper@googlemail.com> wrote:
> Is there a way that we can create a Database file containing our words,
> during development and then use that database within the app, rather than
> having to build the database on first launch?

Yes. Use SQLiteAssetHelper to package a SQLite database in assets/ and
unpack it automatically on first run:

https://github.com/jgilfelt/android-sqlite-asset-helper

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 3.7 Available!

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate