development

Android 기기에서 SQLite 데이터베이스를 보려면 어떻게합니까?

big-blog 2020. 7. 7. 07:14
반응형

Android 기기에서 SQLite 데이터베이스를 보려면 어떻게합니까? [복제]


이 질문에는 이미 답변이 있습니다.

SQLite 데이터베이스에 일련의 데이터가 있습니다. 장치에서 데이터베이스를 볼 필요가 있습니다. 어떻게합니까?

ddms 모드에서 확인했습니다. 파일 탐색기의 데이터가 비어 있습니다.


다음은 단계별 지침입니다 (주로 다른 답변의 조합에서 가져옴). 루팅되지 않은 장치에서도 작동합니다.

  1. 장치를 연결하고 디버그 모드에서 응용 프로그램을 시작하십시오.

  2. adb -d shell "run-as com.yourpackge.name ls /data/data/com.yourpackge.name/databases/"데이터베이스 파일 이름이 무엇인지 확인하는 데 사용할 수 있습니다 .

주의 : com.yourpackge.name 응용 프로그램 패키지 이름입니다. 매니페스트 파일에서 가져올 수 있습니다.

  1. 데이터베이스 파일을 응용 프로그램 폴더에서 SD 카드로 복사하십시오.

    adb -d shell "run-as com.yourpackge.name cat /data/data/com.yourpackge.name/databases/filename.sqlite > /sdcard/filename.sqlite"

주의 : filename.sqlite는 데이터베이스를 만들 때 사용한 데이터베이스 이름입니다.

  1. 데이터베이스 파일을 머신으로 가져 오십시오.

    adb pull /sdcard/filename.sqlite

그러면 SD 카드에서 ADB가있는 위치로 데이터베이스가 복사됩니다.

  1. Firefox SQLite Manager 설치 : https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/

  2. Firefox SQLite Manager (도구-> SQLite Manager)를 열고 위의 3 단계에서 데이터베이스 파일을 엽니 다.

  3. 즐겨!


에서 촬영 여기 , 당신은 시도 할 수 있습니다 :

  1. 페이스 북의 오픈 소스 Stetho 라이브러리

build.gradle에서 :

dependencies {
  // Stetho core
  compile 'com.facebook.stetho:stetho:1.5.1'        
  //If you want to add a network helper
  compile 'com.facebook.stetho:stetho-okhttp:1.5.1'
}

애플리케이션 오브젝트에서 라이브러리를 초기화하십시오.

Stetho.initializeWithDefaults(this);

Chrome에서 데이터베이스를 볼 수 있습니다. chrome://inspect

  1. 다른 옵션은 이 플러그인입니다 (무료 아님).
  2. 그리고 마지막은 브라우저에서 DB 내용을 볼 수있는이 무료 / 오픈 소스 라이브러리입니다 https://github.com/amitshekhariitbhu/Android-Debug-Database

지금까지 찾은 가장 좋은 방법은 Android-Debug-Database 도구를 사용하는 것입니다.

사용 및 설정이 매우 간단하며, 의존성을 추가하고 웹을 통해 장치 데이터베이스의 인터페이스에 연결하기 만하면됩니다. 전화를 루팅하거나 활동을 추가 할 필요가 없습니다. 단계는 다음과 같습니다.

1 단계

앱의 Gradle 파일에 다음 종속성을 추가하고 응용 프로그램을 실행하십시오.

debugCompile 'com.amitshekhar.android:debug-db:1.0.0'

2 단계

브라우저를 열고 포트 8080에서 전화기의 IP 주소를 방문하십시오. URL은 다음과 같아야합니다 http://YOUR_PHONE_IP_ADDRESS:8080. 다음이 제공됩니다.

참고 : 항상 메소드를 호출하여 코드에서 디버그 주소 URL을 얻을 수 있습니다 DebugDB.getAddressLog();

여기에 이미지 설명을 입력하십시오

내 전화기의 IP를 얻으려면 현재 Ping Tools를 사용하지만 많은 대안이 있습니다.

3 단계

그게 다야!


공식 문서에 대한 자세한 내용 : https://github.com/amitshekhariitbhu/Android-Debug-Database


Android 앱 데이터베이스를보고 관리하는 가장 좋은 방법은 DatabaseManager_For_Android 라이브러리를 사용하는 것 입니다.

단일 Java 활동 파일입니다. 소스 폴더에 추가하십시오. 앱 데이터베이스에서 테이블을보고, 테이블에 행을 업데이트, 삭제, 삽입 할 수 있습니다. 앱 내부의 모든 것.

개발이 완료되면 src 폴더에서 Java 파일을 제거하십시오. 그게 다야.

5 분 데모 인 Android SQLite Database 용 데이터베이스 관리자를 볼 수 있습니다 .


당신은 이것을 할 수 있습니다 :

  1. adb shell
  2. cd /go/to/databases
  3. sqlite3 database.db
  4. 에서 sqlite>프롬프트 .tables. 그러면 database.db 파일의 모든 테이블이 제공됩니다.
  5. select * from table1;

실제 기기를 사용하고 있고 루팅되지 않은 경우 FileExplorer보안상의 이유로 폴더가 Android 시스템에 잠겨 있기 때문에 에서 데이터베이스를 볼 수 없습니다 . 그리고 당신은 에뮬레이터에서 그것을 사용하는 경우 당신이 그것을에서 찾을 수 있습니다 FileExplorer, / 데이터 / 데이터 / 패키지 이름 / 데이터베이스 / yourdatabse.db .


AndroidDBvieweR을 사용해보십시오 !

  • 기기를 루팅 할 필요가 없습니다.
  • 응용 프로그램의 데이터베이스 파일을 가져올 필요가 없습니다
  • 몇 가지 구성으로 갈 수 있습니다!

안드로이드 DB 뷰어


SQLite Database Browser사용하여 Android 개발에서 SQLite DB 내용을 확인했습니다. 먼저 장치에서 데이터베이스 파일을 가져 와서 SQLite DB 브라우저에서 열어야합니다.


장치에서 데이터베이스를 직접 볼 수는 없지만 데이터베이스를 로컬 컴퓨터로 덤프하기위한 간단한 셸 스크립트를 게시했습니다.

https://github.com/Pixplicity/dbdump

여기에 설명 된 두 가지 방법이 있습니다.

  1. 먼저 다른 사용자가 파일에 액세스 할 수 있도록하고 장치에서 파일을 가져 오려고 시도합니다.
  2. 실패하면 파일 내용을 터미널을 통해 로컬 시스템으로 스트리밍합니다. \r일부 장치가 셸에 출력하는 문자 를 제거하는 추가 트릭을 수행합니다 .

여기에서 당신은 다음과 같은 CLI 또는 GUI SQLite는 응용 프로그램의 다양한 사용할 수 있습니다 sqlite3또는 sqlitebrowser데이터베이스의 내용을 검색 할 수.


다음과 같이하세요

1 > 여기서 * .jar 파일을 다운로드 하십시오 .

2 > *. jar 파일을 eclipse / dropins / 폴더에 넣고 eclipse를 다시 시작하십시오.

3 > Eclipse 오른쪽 상단에서 DDMS 아이콘을 클릭하십시오.

4 > 왼쪽 패널에서 적절한 에뮬레이터를 선택하십시오.

5 주 패널의 파일 탐색기 탭에서 /data/data/[YOUR.APP.NAMESPACE]/databases로 이동하십시오.

6 > DDMS 아이콘 아래에 데이터베이스를 선택하면 데이터베이스의 새로운 파란색 아이콘이 켜집니다. 그것을 클릭하면 Questoid Sqlite Manager 탭이 열리고 데이터를 볼 수 있습니다.

* 참고 : 데이터베이스에 불이 들어오지 않으면 데이터베이스에 * .db 파일 확장자가 없기 때문일 수 있습니다. 데이터베이스 이름이 [DATABASE_NAME] .db인지 확인하십시오.

* 참고 : .db-Extension없이 DB를 사용하려는 경우 :

이 Questoid SqLiteBrowser : 여기에서 다운로드하십시오 .

-압축을 풀고 이클립스 / 드롭 인 (플러그인이 아닌)에 넣으십시오.

자세한 내용은 여기를 클릭하십시오 .


페이스 북 Stetho를 사용해보십시오.

Stetho는 강력한 Chrome 개발자 도구 등을 지원하는 Android 애플리케이션 용 디버그 브리지입니다.

https://github.com/facebook/stetho


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;
    }
}

3 단계 매니페스트에 등록

<activity
        android:name=".database.AndroidDatabaseManager"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar"/>

4 단계

Intent i = new Intent(this, AndroidDatabaseManager.class);
startActivity(i);

This works with Android 6.0 (debuggable apps at least):

adb shell "run-as your.package.name cp /data/data/your.package.name/databases/you-db-name  /sdcard/file_to_write"

Then you simply can view the DB with aSQLiteManager for instance.


You can try SQLiteOnWeb. It manages your SQLite database in the browser.


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

There is TKlerx's Android SQLite browser for Eclipse, and it's fully functional alongside Android Studio. I'll recommend it, because it is immensely practical.

To install it on Device Monitor, just place the JAR file in [Path to Android SDK folder]/sdk/tools/lib/monitor-[...]/plugins.


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.


I found very simple library stetho to browse sqlite db of app in chrome, see


First post (https://stackoverflow.com/a/21151598/4244605) does not working for me.

I wrote own script for get DB file from device. Without root. Working OK.

  1. Copy script to directory with adb (e.g.:~/android-sdk/platform-tools).
  2. Device have to be connected to PC.
  3. Use ./getDB.sh -p <packageName> for get name of databases.

Usage: ./getDB.sh -p <packageName> -n <name of DB> -s <store in mobile device> for get DB file to this (where script is executed) directory.

I recommend you set filename of DB as *.sqlite and open it with Firefox addon: SQLite Manager.

(It's a long time, when i have written something in Bash. You can edit this code.)

#!/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;

참고 URL : https://stackoverflow.com/questions/19194576/how-do-i-view-the-sqlite-database-on-an-android-device

반응형