我已经检查了ddms模式。文件浏览器中的数据为空。
试试使用Facebook Stetho。
Stetho是一种用于Android应用程序的调试桥,可启用强大的Chrome开发者工具以及更多功能。
步骤1 将这个类复制到你的包中
步骤2 将以下代码放入继承SQLiteOpenHelper的类中。
//-----------------for show databasae table----------------------------------------
public ArrayList<Cursor> getData(String Query)
{
//get writable database
SQLiteDatabase sqlDB =this.getWritableDatabase();
String[] columns = new String[] { "mesage" };
//an array list of cursor to save two cursors one has results from the query
//other cursor stores error message if any errors are triggered
ArrayList<Cursor> alc = new ArrayList<Cursor>(2);
MatrixCursor Cursor2= new MatrixCursor(columns);
alc.add(null);
alc.add (null);
try{
String maxQuery = Query ;
//execute the query results will be save in Cursor c
Cursor c = sqlDB.rawQuery(maxQuery, null);
//add value to cursor2
Cursor2.addRow(new Object[] { "Success" });
alc.set(1,Cursor2);
if (null != c && c.getCount() > 0)
{
alc.set(0,c);
c.moveToFirst();
return alc ;
}
return alc;
}
catch(SQLException sqlEx)
{
Log.d("printing exception", sqlEx.getMessage());
//if any exceptions are triggered save the error message to cursor an return the arraylist
Cursor2.addRow(new Object[] { ""+sqlEx.getMessage() });
alc.set(1,Cursor2);
return alc;
}
catch(Exception ex)
{
Log.d("printing exception",ex.getMessage());
//if any exceptions are triggered save the error message to cursor an return the arraylist
Cursor2.addRow(new Object[] { ""+ex.getMessage() });
alc.set(1,Cursor2);
return alc;
}
}
步骤三 在清单文件中进行注册
<activity
android:name=".database.AndroidDatabaseManager"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar"/>
步骤4
Intent i = new Intent(this, AndroidDatabaseManager.class);
startActivity(i);
这适用于Android 6.0及以上版本(至少可调试应用程序):
adb shell "run-as your.package.name cp /data/data/your.package.name/databases/you-db-name /sdcard/file_to_write"
然后,您可以使用aSQLiteManager等工具轻松查看数据库。
希望这可以帮到你。
在使用终端之前,首先定位您的位置,即Android SDK所在的位置。
eg: C:\Users\AppData\Local\Android\sdk\platform-tools>
然后检查已连接设备的列表,使用以下命令:
adb devices
然后运行此命令将文件从设备复制到您的系统
adb -s YOUR_DEVICE_ID shell run-as YOUR_PACKAGE_NAME chmod -R 777 /data/data/YOUR_PACKAGE_NAME/databases && adb -s YOUR_DEVICE_ID shell "mkdir -p /sdcard/tempDB" && adb -s YOUR_DEVICE_ID shell "cp -r /data/data/YOUR_PACKAGE_NAME/databases/ /sdcard/tempDB/." && adb -s YOUR_DEVICE_ID pull sdcard/tempDB/ && adb -s YOUR_DEVICE_ID shell "rm -r /sdcard/tempDB/*"
Android\sdk\platform-tools\tempDB\databases
有TKlerx的Android SQLite browser for Eclipse,并且它可以与Android Studio完美兼容。我会推荐它,因为它非常实用。
要在设备监视器上安装它,只需将JAR文件放置在[Android SDK文件夹路径]/sdk/tools/lib/monitor-[...]/plugins
中即可。
data-->data-->your.package.name-->databases--->yourdbfile.db
然后您可以使用任何SQLite前端来浏览您的数据库。我使用SQLite Manager Firefox插件。它很好用,小巧又快速。
data-->data-->your.package.name-->databases--->yourdbfile.db
吗? - Hoo第一篇帖子(https://dev59.com/XGIk5IYBdhLWcg3wg-jK#21151598)对我没有用。
我编写了自己的脚本来从设备获取DB文件,而不需要root权限。 运行良好。
〜/android-sdk/platform-tools
)。./getDB.sh -p <packageName>
获取数据库名称。用法:./getDB.sh -p <packageName> -n <name of DB> -s <store in mobile device>
以将DB文件获取到此目录(执行脚本的位置)。
我建议您将DB文件的文件名设置为*.sqlite,并使用Firefox插件:SQLite Manager打开它。
(很长时间以前我写过Bash代码。 您可以编辑此代码。)
#!/bin/sh
# Get DB from Android device.
#
Hoption=false
Poption=false
Noption=false
Soption=false
Parg=""
Narg=""
Sarg=""
#-----------------------FUNCTION--------------------------:
helpFunc(){ #help
echo "Get names of DB's files in your Android app.
Usage: ./getDB -h
./getDB -p packageName -n nameOfDB -s storagePath
Options:
-h Show help.
-p packageName List of databases for package name.
-p packageName -n nameOfDB -s storagePath Save DB from device to this directory."
}
#--------------------------MAIN--------------------------:
while getopts 'p:n:s:h' options; do
case $options in
p) Poption=true
Parg=$OPTARG;;
n) Noption=true
Narg=$OPTARG;;
s) Soption=true
Sarg=$OPTARG;;
h) Hoption=true;;
esac
done
#echo "-------------------------------------------------------
#Hoption: $Hoption
#Poption: $Poption
#Noption: $Noption
#Soption: $Soption
#Parg: $Parg
#Narg: $Narg
#Sarg: $Sarg
#-------------------------------------------------------"\\n
#echo $# #count of params
if [ $Hoption = true ];then
helpFunc
elif [ $# -eq 2 -a $Poption = true ];then #list
./adb -d shell run-as $Parg ls /data/data/$Parg/databases/
exit 0
elif [ $# -eq 6 -a $Poption = true -a $Noption = true -a $Soption = true ];then #get DB file
#Change permissions
./adb shell run-as $Parg chmod 777 /data/data/$Parg/databases/
./adb shell run-as $Parg chmod 777 /data/data/$Parg/databases/$Narg
#Copy
./adb shell cp /data/data/$Parg/databases/$Narg $Sarg
#Pull file to this machine
./adb pull $Sarg/$Narg
exit 0
else
echo "Wrong params or arguments. Use -h for help."
exit 1;
fi
exit 0;
cordova-sqlite-devtools
,这是一个开源CLI,用于从连接的Android设备中提取sqlite数据库。 https://www.npmjs.com/package/cordova-sqlite-devtools - Justin Lettau