How to check database on not rooted android device

2019-01-08 08:38发布

I am developing an app where i am using sqllite3 database to store values. I have Nexus S and Nexus 7 both are unrooted devices. How can i get the database for my app for debugging purpose.

I have tried (1) I have tried all approach mentioned here

adb shell
run-as app.package.name \
cp /data/data/package.name/databases/application.sqlite /sdcard/
exit
adb pull /sdcard/application.sqlite ~/

This says cp not found..

(2) http://developer.android.com/tools/help/adb.html#sqlite

adb -s emulator-5554 shell
# sqlite3 /data/data/com.example.google.rss.rssexample/databases/rssitems.db
SQLite version 3.3.12
Enter ".help" for instructions
.... enter commands, then quit...
sqlite> .exit 

11条回答
女痞
2楼-- · 2019-01-08 08:54

You cannot access /data folder on not-rooted device

There is no way to do that. Android has great security mechanisms. Only your app can access its own files.

查看更多
【Aperson】
3楼-- · 2019-01-08 08:58

The following solution works only for apps that are debuggable. It may not work well on all devices, since ​​run-as command doesn't work on some devices, especially with Jelly Bean.

  1. ​Create a *.bat file and copy the following scripts ​​

    adb shell run-as [package] chmod 777 /data/data/[package]/databases/

    adb shell run-as [package] chmod 777 /data/data/[package]/databases/[db_file_name]

    adb shell run-as [package] cp /data/data/[package]/databases/[db_file_name] /sdcard/

    adb pull /sdcard/[db_file_name]

  2. ​Change [package] to the desired application package

  3. Change [db_file_name] to the desired db name Run the bat file and you should see the copied database in the same folder as the bat file

The above solution assumes:

  • You are working on Windows
  • The device is connected and visible under "adb devices"
查看更多
你好瞎i
4楼-- · 2019-01-08 08:58

I think that this is the easiest way. Add this dependency to your gradle file: debugImplementation 'com.amitshekhar.android:debug-db:1.0.0'

After this when you will start your application in your console you can see the message: D/DebugDB: Open http://192.168.1.114:8080 in your browser

And there is your database.

查看更多
神经病院院长
5楼-- · 2019-01-08 09:00
adb shell "run-as CHR.Droid chmod 666 /data/data/CHR.Droid/files/CHR.db"
adb shell cp /data/data/CHR.Droid/files/CHR.db /sdcard/

In Xamrin.forms I had to replace databases to files

查看更多
叼着烟拽天下
6楼-- · 2019-01-08 09:04

Try using stetho Library developed by facebook , it enables you to view the db via the web browser https://facebook.github.io/stetho/

查看更多
登录 后发表回答