how to see sqlite db with out android device moniter? - android

my android device monitor is not working in android studio, is any other way to see existing sq-lite database,and give the possible reason of my android device monitor issue?.

Its nice question for newbie in android.
For seeing SQLite database you have to follow below step.
Step 1: Setup emulator and run it.
If you have to see SQLite database you must Run your application in
Android Emulator.
(Note:- If you run your application in physical device then you are not able to see database).
Step 2: Now Run you Android Device Monitor from Android studio,now find your android emulator there,click on it and you will show File Explorer in this monitor.
Step 3: In the File Explorer there are Data Folder.Go to Data folder,there is another data folder in it. Now Find your Application here.in your application folder there is folder with name database,Which contain SQLite database file.
(Note: File Explorer>data>data>Your Application Package>database)
Step 4: There are option in the top,From there you can "Pull a file from Device(emulator)",Click on it and save it to your computer.
So here is the file by reading it you can See your database. so,now how can we read it?
Step 5: For reading the file download SQLite Browser from here install it and open it in your computer.
Step 6: In this Browser Click on Open Database and open the file which you have pull from Device(emulator).
So here you can see your database structure and also browse data.
Even, You can update data and Push the file with the Android Device monitor for manually update data.

You can extract your device database in linux (ubuntu) system from the following commands
Note: Make sure your device is connected to adb and showing in adb devices list
adb backup -f ~/data.ab -noapk <your app package name ex app.package.name>
dd if=data.ab bs=1 skip=24 | openssl zlib -d | tar -xvf -
The first command will create a data.ab file in home directory and second command should be run from the home directory as data.ab file is in that directory after running second command there will be a app folder created in your home directory, you can see your app package name directory under it and file your db file and shared preference xml.

You can use navicate premium to create explore and query to sqlite db.
In go to file explore of your emulator go to data > data > your app and database folder extract it to your computer and open in navicate.

Related

How can I read my app's database file from device?

I am writing an Android application using SQLite. How to view the .db file that's on the device without rooting it?
I tried Questiod SQLite Manager but "data/data/(my application name)/.db" cannot be opened. The method seems to be used for emulator and rooted devices only. I am using an unrooted device for debugging.
Screen for DDMS:
In your manifest file, add a property 'debuggable=true' in application tag. Then find your database in your given path.
I assume you mean for debugging?
You could copy the database file to a non-private directory (for example into the one returned by Context.getExternalFilesDir(). Afterwards you can use adb pull to copy it to your development machine.
Install this APK into your emulator and read your DB file and also add,update,delete record of your database
Yes , there are 2 methods from which u can view ur db data :
Go To DDMS -> Data -> Data -> Select ur Package ->Databases -> Pull them Out and view with SQlite Broswer
OR
Install Root Apk in ur bluestack and view in device or emulator itself..
From Command Prompt you can try this
Open cmd
Go into 'Platform tools'
Type 'adb shell'
su
Press 'Allow' on device
chmod 777 /data /data/data /data/data/com.application.package /data/data/com.application.package/*
Open DDMS view in Eclipse and from there open 'FileExplorer' to get your desired file
You can view (visualize) the data in the .db file by using the software called "DB Browser for SQLITE"
get your .db file from the device(smartphone) memory (by accessing the DDMS --> File explore)
download and install sqlitebrowser (http://sqlitebrowser.org/)
after installing, open "DB Browser for SQLITE" and go to "open database" to load your .db file
Choose the "Browse data" tab
Finally, select the table you want to visualize to display the data in the database.

View SQLite DB on Android device

ALL,
I have an Eclipse Kepler where I am developing my Android application. This application uses SQLite for data persistence.
What I'd like to do is to see the database/tables/data inside Eclipse.Following this I opened installed the plugin, then opened File Explorer.
Problem is: trying to open /data is unsuccessful. It does not open.
Do I have to root the device to open this directory? I have LG phone with Android 2.2.
Permission sets for this folder is drwxrwx--x.
Thank you.
[EDIT]
I also tried to run the shell
igor#IgorReinCloud ~ $ android_sdk/platform-tools/adb -d shell
$ sqlite3 /data/data/com.radar.radar/databases/friends.db
sqlite3: permission denied
$
So it actually means that this is a permission issue and therefor I will not be able to see the db.
[/EDIT]
you can try
$ adb -d shell
$ run-as [your-package-name]
This should allow you to run commands as the user for that package. No guarantees though. Also, I've found that not all devices appear to have sqlite3 available through the shell.
Another possibility is to do the run-as command as above, then copy the database file to /sdcard, whcih is public. Then you can do adb pull /sdcard/[database-file]. Then you'll have the file on your local machine and can use sqlite3 there.
Using this simple library you can directly view your SQLlite datbase from your app . no need to extra .db file
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.
When the development is done remove the java file from your src folder thats it .
It helped me a lot .Hope it helps you too .
You can view the 1 minute demo here : http://youtu.be/P5vpaGoBlBY

Android studio file explorer not showing files in data folder

I am using android studio and 'samsung tab 2' as my testing device. I want to see the files of my application. So i clicked the 'Monitor' button. Then i selected my device from device list and selected my application package.There is a Data folder in file explorer. But when i clicked on the data folder it shows nothing.When i run this application using emulator the file explorer shows the data folder and i can see every files in my application. how can i see my files inside the data folder when using device ?
I found a solution based on the answer in stack overflow .
How to access data/data folder in Android device?
First i rooted the device .Then i modify the access permission of data folder using adb shell.
the code is
$ adb shell
$ su
# mount -o rw
1|root#android:/ # chmod -R 777 data/
Now i can access the files.Thank you #param for your valuable comment.

Getting SQLite database from emulator (data/data/package_name/databases) to local drive

I would like to edit my app's DB using the SQLite Browser. I'm able to edit the DB using the adb shell (sqlite3), but I would rather edit it using a GUI rather than a command line. How do I get the DB from the emulator to a local drive? As of now I've tried:
1) using the adb pull command to pull the database from the emulator to my local drive.
adb pull data/data/com.myapps.quiz c:/
This command executes correctly, but I'm not able to find the file or directory in the local drive I specified.
2) Used the DDMS Perspective to locate the file in the File Explorer, but every time I get into the data/data directory, I only see directories called "con". I even tried pulling the entire data/data directory, but I can't find the name of the package (com.myapps.quiz) where the database is stored.
What am I missing here? Any help you could provide would be most helpful!
Your database is secure to your package so you cannot get this directly.
I have a work around for this.
What I do is go to shell and run-as my package and copy the database to sdcard using cat
adb shell
run-as your.package.name
cd databases
cat your_database.db > /mnt/sdcard/your_database.db
And I pull the file from the sdcard using File Explorer
Are you sure you're connecting to the emulator instance in DDMS, and not an actual device? I have always been able to push and pull sqlite databases from the
data/data/com.my.package/databases/mydb.sqlite
directory, and I can't think of any setting that would override that. An alternative would be to root an actual phone and then you will be able to move anything from the phone to your computer.

Where does Android emulator store SQLite database?

I'm working on an Android application that stores data in a SQLite database. My question is, where does this database file get stored on the filesystem when you're using an emulator?
I have seen that it's stored in
/data/data/package_name/databases
but I need to know where on my local machine's hard drive that actually maps to. The database persists on multiple runs of the emulator, even after having shut down the machine, so it can't just reside in RAM...
An update mentioned in the comments below:
You don't need to be on the DDMS perspective anymore, just open the File Explorer from Eclipse Window > Show View > Other... It seems the app doesn't need to be running even, I can browse around in different apps file contents. I'm
running ADB version 1.0.29
Or, you can try the old approach:
Open the DDMS perspective on your Eclipse IDE
(Window > Open Perspective > Other > DDMS)
and the most important:
YOUR APPLICATION MUST BE RUNNING SO YOU CAN SEE THE HIERARCHY OF FOLDERS AND FILES.
Then in the File Explorer Tab you will follow the path :
data > data > your-package-name > databases > your-database-file.
Then select the file, click on the disket icon in the right corner of the screen to download the .db file. If you want to upload a database file to the emulator you can click on the phone icon(beside disket icon) and choose the file to upload.
If you want to see the content of the .db file, I advise you to use SQLite Database Browser, which you can download here.
PS: If you want to see the database from a real device, you must root your phone.
The filesystem of the emulator doesn't map to a directory on your hard drive. The emulator's disk image is stored as an image file, which you can manage through either Eclipse (look for the G1-looking icon in the toolbar), or through the emulator binary itself (run "emulator -help" for a description of options).
You're best off using adb from the command line to jack into a running emulator. If you can get the specific directory and filename, you can do an "adb pull" to get the database file off of the emulator and onto your regular hard drive.
Edit: Removed suggestion that this works for unrooted devices too - it only works for emulators, and devices where you are operating adb as root.
The other answers are severely outdated. With Android Studio, this is the way to do it:
Click on Tools > Android > Android Device Monitor
Click on File Explorer
Navigate to your db file and click on the Save button.
In Android Studio 3.4.1, you can use the search feature of Android Studio to find "Device File Explorer" and then go to the /data/data/package_name/database directory of your emulator.
I wrote a simple bash script, which pulls database from android device to your computer (Linux, Mac users)
filename:android_db_move.sh
usage: android_db_move.sh com.example.app db_name.db
#!/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
Since the question is not restricted to Android Studio, So I am giving the path for Visual Studio 2015 (worked for Xamarin).
Locate the database file mentioned in above image, and click on Pull button as it shown in image 2.
Save the file in your desired location.
You can open that file using SQLite Studio or DB Browser for SQLite.
Special Thanks to other answerers of this question.
The databases are stored as SQLite files in /data/data/PACKAGE/databases/DATABASEFILE where:
PACKAGE is the package declared in the AndroidManifest.xml (tag "manifest", attribute "package")
DATABASEFILE is the name passed when you call the SQLiteOpenHelper constructor as explained here: http://developer.android.com/guide/topics/data/data-storage.html#db
You can see (copy from/to filesystem) the database file in the emulator selecting DDMS perspective, in the File Explorer tab.
Simple Solution - works for both Emulator & Connected Devices
1 See the list of devices/emulators currently available.
$ adb devices
List of devices attached
G7NZCJ015313309 device emulator-5554 device
9885b6454e46383744 device
2 Run backup on your device/emulator
$ adb -s emulator-5554 backup -f ~/Desktop/data.ab -noapk com.your_app_package.app;
3 Extract data.ab
$ dd if=data.ab bs=1 skip=24 | openssl zlib -d | tar -xvf -;
You will find the database in /db folder
according to Android docs, Monitor was deprecated in Android Studio 3.1 and removed from Android Studio 3.2. To access files, there is a tab in android studio called "Device File Explorer" bottom-right side of developing window which you can access your emulator file system. Just follow
/data/data/package_name/databases
good luck.
For Android Studio 3.5, fount it using instructions here: https://developer.android.com/studio/debug/device-file-explorer
(View -> Tool Windows -> Device File Explorer -> -> databases

Categories

Resources