I'm trying this with my Nexus One. I have the android SDK and have used the command adb pull /data/data/com.myapp.android/databases C:\pulls but all I get is pull: building file list... 0 files pulled. 0 files skipped. Also, it seems no matter how much data I add to the tutorial NotePad app I installed, the data size for the app (as shown in Settings) never exceeds 8KB. How is this possible? Is there some other place where databases are stored? When I use the File Explorer view (that's part of ADT) in Eclipse, I see there's nothing in /data. To add a twist, I have no trouble pulling any other files from the device. It's just databases I have trouble with. Am I missing something? Thanks much.
我用Nexus One试试这个。我有android SDK,使用的是命令adb pull /data/data/com.myapp。C:\pull,但我得到的只是pull:构建文件列表……0文件了。0文件跳过。此外,似乎无论我向我安装的教程NotePad应用程序添加多少数据,该应用程序的数据大小(如图设置所示)都不会超过8KB。这怎么可能?还有其他存储数据库的地方吗?当我在Eclipse中使用File Explorer视图(这是ADT的一部分)时,我发现/data中什么都没有。要添加一个扭转,我可以从设备中取出任何其他文件。只是数据库有问题。我遗漏了什么东西?谢谢。
3 个解决方案
#1
10
Accessing internal storage is not possible unless your phone is rooted. One simple way is to use the emulator, and then you can get at the files. For getting a database off the device I wrote a little utility and put in some debug UI for it:
访问内部存储是不可能的,除非你的手机是根。一种简单的方法是使用仿真器,然后您可以获取文件。为了将数据库从设备中取出,我编写了一个小实用程序,并为它添加了一些调试UI:
private void backupDb() throws IOException {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "/data/com.yourcompany.yourapp/databases/yourapp.db";
String backupDBPath = "/yourapp_logs/yourapp.db";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
if (backupDB.exists())
backupDB.delete();
if (currentDB.exists()) {
makeLogsFolder();
copy(currentDB, backupDB);
}
dbFilePath = backupDB.getAbsolutePath();
}
}
private void makeLogsFolder() {
try {
File sdFolder = new File(Environment.getExternalStorageDirectory(), "/yourapp_logs/");
sdFolder.mkdirs();
}
catch (Exception e) {}
}
private void copy(File from, File to) throws FileNotFoundException, IOException {
FileChannel src = null;
FileChannel dst = null;
try {
src = new FileInputStream(from).getChannel();
dst = new FileOutputStream(to).getChannel();
dst.transferFrom(src, 0, src.size());
}
finally {
if (src != null)
src.close();
if (dst != null)
dst.close();
}
}
#2
0
Create a "pull.bat" file in your windows desktop.
创建一个“拉。在你的windows桌面拍“文件”。
In the file put:
文件中说:
db pull /data/com.APPNAME/databases/DBNAME.sqlite
pause
#3
0
If you are using MAC or Linux try this script. This doesn't require root permissions
如果您正在使用MAC或Linux,请尝试此脚本。这并不需要root权限
#!/bin/bash
REQUIRED_ARGS=2
ADB_PATH=/Users/Tadas/Library/sdk/platform-tools/adb
PULL_DIR="~/"
if [ $# -ne $REQUIRED_ARGS ]
then
echo ""
echo "Usage:"
echo "android_db_move.sh [package_name] [db_name]"
echo "eg. android_db_move.sh lt.appcamp.impuls impuls.db"
echo ""
exit 1
fi;
echo""
cmd1="$ADB_PATH -d shell 'run-as $1 cat /data/data/$1/databases/$2 > /sdcard/$2' "
cmd2="$ADB_PATH pull /sdcard/$2 $PULL_DIR"
echo $cmd1
eval $cmd1
if [ $? -eq 0 ]
then
echo ".........OK"
fi;
echo $cmd2
eval $cmd2
if [ $? -eq 0 ]
then
echo ".........OK"
fi;
exit 0
#1
10
Accessing internal storage is not possible unless your phone is rooted. One simple way is to use the emulator, and then you can get at the files. For getting a database off the device I wrote a little utility and put in some debug UI for it:
访问内部存储是不可能的,除非你的手机是根。一种简单的方法是使用仿真器,然后您可以获取文件。为了将数据库从设备中取出,我编写了一个小实用程序,并为它添加了一些调试UI:
private void backupDb() throws IOException {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "/data/com.yourcompany.yourapp/databases/yourapp.db";
String backupDBPath = "/yourapp_logs/yourapp.db";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
if (backupDB.exists())
backupDB.delete();
if (currentDB.exists()) {
makeLogsFolder();
copy(currentDB, backupDB);
}
dbFilePath = backupDB.getAbsolutePath();
}
}
private void makeLogsFolder() {
try {
File sdFolder = new File(Environment.getExternalStorageDirectory(), "/yourapp_logs/");
sdFolder.mkdirs();
}
catch (Exception e) {}
}
private void copy(File from, File to) throws FileNotFoundException, IOException {
FileChannel src = null;
FileChannel dst = null;
try {
src = new FileInputStream(from).getChannel();
dst = new FileOutputStream(to).getChannel();
dst.transferFrom(src, 0, src.size());
}
finally {
if (src != null)
src.close();
if (dst != null)
dst.close();
}
}
#2
0
Create a "pull.bat" file in your windows desktop.
创建一个“拉。在你的windows桌面拍“文件”。
In the file put:
文件中说:
db pull /data/com.APPNAME/databases/DBNAME.sqlite
pause
#3
0
If you are using MAC or Linux try this script. This doesn't require root permissions
如果您正在使用MAC或Linux,请尝试此脚本。这并不需要root权限
#!/bin/bash
REQUIRED_ARGS=2
ADB_PATH=/Users/Tadas/Library/sdk/platform-tools/adb
PULL_DIR="~/"
if [ $# -ne $REQUIRED_ARGS ]
then
echo ""
echo "Usage:"
echo "android_db_move.sh [package_name] [db_name]"
echo "eg. android_db_move.sh lt.appcamp.impuls impuls.db"
echo ""
exit 1
fi;
echo""
cmd1="$ADB_PATH -d shell 'run-as $1 cat /data/data/$1/databases/$2 > /sdcard/$2' "
cmd2="$ADB_PATH pull /sdcard/$2 $PULL_DIR"
echo $cmd1
eval $cmd1
if [ $? -eq 0 ]
then
echo ".........OK"
fi;
echo $cmd2
eval $cmd2
if [ $? -eq 0 ]
then
echo ".........OK"
fi;
exit 0