如何从 android 设备中提取 sqlite 数据库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11598152/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I pull the sqlite database from the android device?
提问by Manikandan Palanisamy
How do I pull the sqlite database from the android device like emulator?
如何从模拟器之类的 android 设备中提取 sqlite 数据库?
回答by Manmohan Soni
You can use these commands for pulling the data base from your device. Typing these commands through android studio is very easy. Please make sure you have set the path of adb globally to your system. Then open the "terminal" window from bottom to android studio and near to "Android Monitor". Now you just update the following commands with actual package name of your app and database file name. You will get your file out from the device.
您可以使用这些命令从您的设备中提取数据库。通过 android studio 输入这些命令非常简单。请确保您已将 adb 的路径全局设置为您的系统。然后从底部打开“终端”窗口到android studio,靠近“Android Monitor”。现在,您只需使用应用程序的实际包名和数据库文件名更新以下命令。您将从设备中取出文件。
adb shell "run-as package.name chmod 666 /data/data/package.name/databases/file"
adb pull /data/data/package.name/databases/file .
adb shell "run-as package.name chmod 600 /data/data/package.name/databases/file"
the command for Android 5.0+ /data/data/package.name/databases/file would be:
Android 5.0+ /data/data/package.name/databases/file 的命令是:
adb shell "run-as package.name chmod 666 /data/data/package.name/databases/file"
adb exec-out run-as package.name cat databases/file > newOutFileName
adb shell "run-as package.name chmod 600 /data/data/package.name/databases/file"
回答by biegleux
- connect your device to pc
- open command prompt in
/sdk-directory/tools
- type
adb pull /data/data/com.example.app/databases/database.db
- 将您的设备连接到电脑
- 在中打开命令提示符
/sdk-directory/tools
- 类型
adb pull /data/data/com.example.app/databases/database.db
where com.example.app
is your application package name and database.db
is the database file
com.example.app
您的应用程序包名称和database.db
数据库文件在哪里
that's in case your device is rooted, if not try following
以防万一您的设备已植根,否则请尝试以下
回答by Moaz Rashad
You can use Android Device Monitor to pull it. Go to Tools -> Android -> Android Device Monitor
您可以使用 Android Device Monitor 来拉取它。转到工具 -> Android -> Android 设备监视器
- Select your device from the left list.
- Select FileExplorer tab
- Expand data-> data -> "yourpackageName" -> databases
- Select your databaseFile and on the top right click on this icon
pull a file form a device.
- Save it on your desk then use this tool to open it: http://sqlitebrowser.org/
- 从左侧列表中选择您的设备。
- 选择 FileExplorer 选项卡
- 展开数据-> 数据-> "yourpackageName" -> 数据库
- 选择您的数据库文件并在右上角单击此图标
从设备中拉出文件。
- 将其保存在您的办公桌上,然后使用此工具将其打开:http: //sqlitebrowser.org/
回答by sanath_p
The best way to view and manage you android app database is to use this library https://github.com/sanathp/DatabaseManager_For_Android
查看和管理您的 android 应用程序数据库的最佳方法是使用此库https://github.com/sanathp/DatabaseManager_For_Android
Its a single java activity file ,just add the java file to your source folder you can view the tables in your app database , update ,delete, insert rows to you table .Everything from your app.
它是一个单一的 java 活动文件,只需将 java 文件添加到您的源文件夹中,您就可以查看应用程序数据库中的表、更新、删除、向表中插入行。应用程序中的所有内容。
When the development is done remove the java file from your src folder thats it .
开发完成后,从 src 文件夹中删除 java 文件。
It helped me a lot .Hope it helps you too .
它帮助了我很多。希望它也能帮助你。
You can view the 1 minute demo here : http://youtu.be/P5vpaGoBlBY
您可以在此处查看 1 分钟演示:http: //youtu.be/P5vpaGoBlBY
回答by Logic Luo
adb root
adb remount
adb pull <remote> <local>
回答by abdimuna
I know this is an old question, however this is what I did to pull the SQLite Database file from app on device.
我知道这是一个老问题,但是这是我从设备上的应用程序中提取 SQLite 数据库文件的方法。
- Saving the file from app package to device sdcard
- 将文件从应用程序包保存到设备 SD 卡
adb -d shell "run-as com.dautechnology.abdimuna.smartparking cat /data/data/<myAppPackageName>/databases/<databaseFileName> > /sdcard/<databaseFileName>"
adb -d shell "run-as com.dautechnology.abdimuna.smartparking cat /data/data/<myAppPackageName>/databases/<databaseFileName> > /sdcard/<databaseFileName>"
The above command will store file to /sdcard
You can verify the file by
adb shell
ls sdcard/
Then exit from adb shell by typing exit
上面的命令会将文件存储到 /sdcard 您可以通过以下方式验证文件
adb shell
ls sdcard/
然后通过键入退出 adb shellexit
- Pull the file from sdcard to your current working location.
- 将文件从 sdcard 拉到您当前的工作位置。
adb pull sdcard/<databaseFileName>
adb pull sdcard/<databaseFileName>
- Move the file to Desktop or place of your desire.
- 将文件移动到桌面或您想要的地方。
mv <databseFileName> ~/Desktop
mv <databseFileName> ~/Desktop
I hope this helps someone out there.
我希望这可以帮助那里的人。
回答by Emre
You can skip all those middle stages with one command.
您可以使用一个命令跳过所有这些中间阶段。
In your PC shell run:
在你的 PC shell 中运行:
adb -d shell 'run-as <package_name> cat /data/data/<package_name>/databases/<db_name>' > <local_file_name>
回答by Tushar Saha
from version 24 onwards i use these commands to pull database
从版本 24 开始,我使用这些命令来拉取数据库
adb shell
run-as package.name
cat /databases/database.db > /sdcard/database.db
exit
exit
adb pull /sdcard/database.db
prior to version 24
版本 24 之前
adb pull /data/data/package name/databases/database.db
was sufficient
足够了
回答by Mohammod Hossain
If you use eclipse then go to DDMS view . from File Explorer Tab ->data->data->application package name->databases-> databse name
如果您使用 Eclipse,则转到 DDMS 视图。从文件资源管理器选项卡->数据->数据->应用程序包名称->数据库->数据库名称
select database db file then click pull button
选择数据库db文件然后单击拉按钮
回答by SARATH V
Do it programatically in application
在应用程序中以编程方式执行
try {
File file = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (file.canWrite()) {
String currentPath = "/data/data/" + getPackageName() + "/databases/yourdbname";
String copyPath = "copydb_name.db";
File currentDB = new File(currentPath);
File backupDB = new File(file, copyPath);
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) {
}
Make sure given permission
确保获得许可
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>