Teekam
Teekam

Reputation: 939

Where is sqlite database in android tablet?

I am developing a application in which, insert some values in local sqlite database. Its working fine on local Emulator and Tablet as well as. After inserting values, I want to get sqlite database. I am able to get database from Emulator but unfortunatally unable to get sqlite database from Android Tablet. Please suggest what is procedure to get database from real device(Tablet).

Thanks.

Upvotes: 2

Views: 4853

Answers (5)

Teekam
Teekam

Reputation: 939

Thank for all of you

Finally i got a proper solution. We can't get db from any (Samsung) tablet, but we can copy its data and can pull to our PC.

public void copyDataBase() {
        Log.i("info", "in copy data base at finally");
        try {
            File sd = Environment.getExternalStorageDirectory();
            File data = Environment.getDataDirectory();
            if (sd.canWrite()) {
                String currentDBPath = "/data/" + context.getPackageName()
                        + "/databases/DB_29Apr.sqlite";
                String backupDBPath = "DB_29Apr.sqlite";
                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());
                    src.close();
                    dst.close();
                }
            }
        } catch (Exception e) {
            Log.i("info", "in copy of bata base 10 ");

        }
    }

From above function you can copy the db on external space of tablet.

Go to DDMS and find the defined database with given name in db at storage place in tablet.

Upvotes: 2

Bhavdip Sagar
Bhavdip Sagar

Reputation: 1971

reason you can not able because it would created in following location like

/data/data/<your root package name in android manifest file>/databases/< you database name>

which can only accessed by your application so simply copy you file from above location to sd card location Programmatically use below function might be help for copy stream

public static void CopyStream(InputStream is, OutputStream os) {
    final int buffer_size = 1024;
    try {
        byte[] bytes = new byte[buffer_size];
        for (;;) {
            int count = is.read(bytes, 0, buffer_size);
            if (count == -1)
                break;
            os.write(bytes, 0, count);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

Upvotes: 1

Bhavdip Sagar
Bhavdip Sagar

Reputation: 1971

FYI In Tablet device for security purpose it does not allow to find you .db file. If you are using emulator then you have permission to access location[directory] of database.

This is final answer.

Thank you

Upvotes: 1

Narendra Pal
Narendra Pal

Reputation: 6604

You have to select this from FileExplorer mnt---> sdcard---> your DB_NAME

Upvotes: 1

MysticMagicϡ
MysticMagicϡ

Reputation: 28823

Create one folder named database manually in your tablet sdcard. Then run your application and then open the database folder to get .db file.

Upvotes: 1

Related Questions