Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android export SQLite Database to Computer / Mac

I have a SQLite Database on my Android Device (My own App). Now i want to see the SQLite Database on my Computer.

Is there any solution ( easy way ) to get the Database without root rights and without a SD-Card on my Computer?

I tried to google it but i can't find any solution for this problem....

Edit: I'm using not the Emulator ( need the Camera on my Device).

like image 342
FunkyMan Avatar asked Mar 31 '16 07:03

FunkyMan


3 Answers

if phone is not rooted you cant access directly your DB, but you can copy it to download folder, then, copy to PC

public static void copyAppDbToDownloadFolder(Activity ctx) throws IOException {
    File backupDB = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
            "databse_name.db"); // for example "my_data_backup.db"
    File currentDB = getApplicationContext().getDatabasePath("databasename.db");
    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();
    }
}
like image 77
khyper Avatar answered Oct 21 '22 16:10

khyper


This method worked for my unrooted device.

# check if your device connected
adb devices

adb shell

run-as  your.package.name

chmod 777 databases/your.database.name

exit

cp /data/data/your.package.name/your.database.name /mnt/sdcard/

exit

adb pull /mnt/sdcard/your.database.name
like image 5
crashOveride Avatar answered Oct 21 '22 16:10

crashOveride


If you are saving Sqlite DB in default location , you can find the same in path like following

/data/data/com.dev.myapplication/databases/mydb.db

You can find the same using Android Device Monitor, through which you can navigate to both internal and external memory.

Once you find the database file, extract the same and save in desktop after connecting through USB cable. You can use option "Pull a file from device"

enter image description here

Once you have extracted file to desktop, use any tools similar to Mozilla Firefox SQLite viewer to view database.

like image 1
Sreehari Avatar answered Oct 21 '22 16:10

Sreehari