How do I view the SQLite database on an Android de

2019-01-01 07:58发布

This question already has an answer here:

I have a set of data in an SQLite database. I need to view the database on a device. How do I do that?

I have checked in ddms mode. The data in file explorer is empty.

20条回答
素衣白纱
2楼-- · 2019-01-01 08:40

Follow these steps

1>Download the *.jar file from here .

2>Put the *.jar file into the folder eclipse/dropins/ and Restart eclipse.

3>In the top right of eclipse, click the DDMS icon.

4>Select the proper emulator in the left panel.

5In the File Explorer tab on the main panel, go to /data/data/[YOUR.APP.NAMESPACE]/databases.

6>Underneath the DDMS icon, there should be a new blue icon of a Database light up when you select your database. Click it and you will see a Questoid Sqlite Manager tab open up to view your data.

*Note: If the database doesn't light up, it may be because your database doesn't have a *.db file extension. Be sure your database is called [DATABASE_NAME].db

*Note: if you want to use a DB without .db-Extension:

-Download this Questoid SqLiteBrowser: Download fro here.

-Unzip and put it into eclipse/dropins (not Plugins).

-Check this for more information Click here.

查看更多
ら面具成の殇う
3楼-- · 2019-01-01 08:40

Using file explorer, you can locate your database file like this:

data-->data-->your.package.name-->databases--->yourdbfile.db

Then you can use any SQLite fronted to explore your database. I use the SQLite Manager Firefox addon. It's nice, small, and fast.

查看更多
墨雨无痕
4楼-- · 2019-01-01 08:43

The best way to view and manage your Android app database is to use the library DatabaseManager_For_Android.

It's a single Java activity file; just add it to your source folder. You can view the tables in your app database, update, delete, insert rows to you table. Everything from inside your app.

When the development is done remove the Java file from your src folder. That's it.

You can view the 5 minute demo, Database Manager for Android SQLite Database .

查看更多
其实,你不懂
5楼-- · 2019-01-01 08:45

If you don't want to use

  1. adb
  2. 3rd party library or
  3. gradle dependency etc

and just want the database file in your SDCard, this is the solution.

copy the class DatabaseUtil.java in your project

package com.util;

import android.content.Context;
import android.os.Environment;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

/**
 * Shayan Rais (http://shanraisshan.com)
 * created on 8/17/2016
 */
public class DatabaseUtil {
    //You need to declare permission
    // <uses-permission     android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    //in your Manifest file in order to use this class

    //______________________________________________________________________________________________

    //todo -> rename the database according to your application
    final static String DATABASE_NAME = "MyDatabase.sqlite";
    //example WhatsApp :  /data/data/com.whatsapp/databases/msgstore.db
    final static String FOLDER_EXTERNAL_DIRECTORY = Environment.getExternalStorageDirectory() + "/shanraisshan";

    //______________________________________________________________________________________________
    public static void copyDatabaseToExtStg(Context ctx) {
        //external storage file
        File externalDirectory = new File(FOLDER_EXTERNAL_DIRECTORY);
        if(!externalDirectory.exists())

        .
        .

and simply call copyDatabaseToExtStg() method from any activity in your app


this will copy the database folder at location sdcard/shanraisshan/your_database_file

Image shows MyDatabase.sqlite present in SD Card


For further detailed explanation check Android-Database-Viewer on Github. https://github.com/shanraisshan/Android-Database-Viewer

查看更多
像晚风撩人
6楼-- · 2019-01-01 08:45

Although this doesn't view the database on your device directly, I've published a simple shell script for dumping databases to your local machine:

https://github.com/Pixplicity/dbdump

It performs two distinct methods described here:

  1. First, it tries to make the file accessible for other users, and attempting to pull it from the device.
  2. If that fails, it streams the contents of the file over the terminal to the local machine. It performs an additional trick to remove \r characters that some devices output to the shell.

From here you can use a variety of CLI or GUI SQLite applications, such as sqlite3 or sqlitebrowser, to browse the contents of the database.

查看更多
看风景的人
7楼-- · 2019-01-01 08:49

Hope this helps you

Using Terminal First point your location where andriod sdk is loacted

eg: C:\Users\AppData\Local\Android\sdk\platform-tools>

then check the list of devices attached Using

 adb devices

and then run this command to copy the file from device to your system

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/*"

You can find the database file in this path

 Android\sdk\platform-tools\tempDB\databases
查看更多
登录 后发表回答