简体   繁体   English

Android将SQLite数据库导出到计算机/ Mac

[英]Android export SQLite Database to Computer / Mac

I have a SQLite Database on my Android Device (My own App). 我的Android设备上有一个SQLite数据库(我自己的应用程序)。 Now i want to see the SQLite Database on my Computer. 现在我想在我的电脑上看到SQLite数据库。

Is there any solution ( easy way ) to get the Database without root rights and without a SD-Card on my Computer? 有没有任何解决方案(简单的方法)来获得没有root权限的数据库,并且我的计算机上没有SD卡?

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 如果手机没有root,则无法直接访问您的数据库,但您可以将其复制到下载文件夹,然后复制到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设备

adb shell adb shell

run-as your.package.name run-as your.package.name

chmod 777 databases/your.database.name chmod 777 databases / your.database.name

exit 出口

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

exit 出口

adb pull mnt/sdcard/your.database.name 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 如果要将Sqlite DB保存在默认位置,则可以在路径中找到相同的内容,如下所示

/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. 您可以使用Android设备监视器找到相同的内容,通过它可以导航到内部和外部内存。

Once you find the database file, extract the same and save in desktop after connecting through USB cable. 找到数据库文件后,通过USB线连接后将其解压缩并保存在桌面上。 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. 将文件解压缩到桌面后,使用类似于Mozilla Firefox SQLite查看器的任何工具来查看数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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