Let me give a feature to my android application that instantly supports the sqlite database towards the sdcard.

What's the easiest method to build a storage shed? Any good examples/lessons available?

This code works best for me!

    try {
        File sd = Environment.getExternalStorageDirectory();
        File data = Environment.getDataDirectory();

        if (sd.canWrite()) {
            String currentDBPath = "\\data\\{package name}\\databases\\{database name}";
            String backupDBPath = "{database name}";
            File currentDB = new File(data, currentDBPath);
            File backupDB = new File(sd, backupDBPath);

            if (currentDB.exists()) {
                FileChannel src = new FileInputStream(currentDB).getChannel();
                FileChannel dst = new FileOutputStream(backupDB).getChannel();
                dst.transferFrom(src, 0, src.size());
    } catch (Exception e) {

Does anybody determine if this works on non-root phones? I've only attempted it on the rooted G1.

SQLite databases are completely self-contained files and therefore are portable &mdash you can easily copy the whole file right to the Sdcard.

Though first I'd check whether an Sdcard is set up in the unit, and what its path is (using Environment.getExternalStorageDirectory()).

There is a code for conveying the sqlite db to xml around the sdcard. It can be adequate?

My response up answer (sorry there does not appear to become a way that i can comment directly) could be "Great, so - how can you do this?Inch How can you obtain the title from the database file, and copy it somewhere around the card?

I clarified an issue such as this having a method you can put inside your SQLiteOpenHelper. It is actually copying the db file from some type of exterior storage, towards the internal application storage. There's several extra code that opens and reads the db file to make certain it is incorporated in the proper condition for Android to create database calls into it.


st.transferFrom(src, 0, src.size());

works fine on my small unrooted HTC Hero with android 2.1 update1.

I'm not sure what goes on when the phone is rooted or otherwise however, you should write your files to:


This works be it rooted or otherwise.