简体   繁体   中英

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).

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();
    }
}

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

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"

在此输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM