안드로이드에서 기본적으로 사용하는 DB 파일을 직접 접근하거나 SQLite3 명령어로 직접 읽어 오면 안 되지요.
Provider를 통해서 호출해야 하는 것이 정석인데요.
안드로이드 사이트의 설명만 봐서는 잘 와 닿지 않은 것이 사실 입니다.
기본제공하는 Provider는 어떻게 동작하는지 분석할 때도 DB 구조를 알면 도움이되고,
실제 테이블에 어떤 필드가 있는지?
실제 데이타가 들어가면 어떻값이 들어가는지?
이런것을 알면 아무래도 도움이 되겠지요.
그래서, 아래 방법대로 진행을 하시면 DB 분석에 조금이나마 편할 듯 하여 방법을 올립니다.
1. DB 파일 생성.
우선 안드로이드의 db 파일들은 처음부터 있는 것이 아니라 프로그램을 실행하고 어떤조건이 되어야 생깁니다.
예들 들면, audio, video, image 등은 sdcard에 데이타 넣두고, media scanner를 실행해야 생기지요.
그러므로, 원하는 db파일이 생기도록 프로그램을 사용해야 합니다.
여기서 예는 video 파일을 하겠습니다.
sdcard에 안드로이드에서 재생가능한 동영상 파일을 넣고,
설정에서 media scanner를 실행합니다.
여기까지만 해도 되지만, Gallery 들어가서 재생되는지 까지 확인하면 더 좋겠지요.
혹은 재생 안되는, 지원하지 않는 파일을 넣어서 해 보는 것도 좋구요^^
2. DB 파일을 PC로 가져오기
물론, adb shell 이나 SQLite3 명령어 등을 잘 아시면 명령라인 명령어들로도 충분이 확인이 가능합니다.
그래도, 보기 편한 툴을 사용하면 조금더 쉽겠죠 ^^
adb shell 을 이용하여 db 파일의 위치를 확인합니다.
# ls
ls
internal.db
external-12e23719.db
# pwd
pwd
/data/data/com.android.providers.media/databases
#
위와 같이 안드로이드의 기본 media provider의 db 파일이 있는 위치와 파일명을 확인 하였습니다.
그럼, 위 파일을 PC로 복사해 줍니다.
D:\>adb pull /data/data/com.android.providers.media/databases/external-12e23719.db .
전 external-?????.db 파일을 복사해 왔습니다 ^^
원하시는 파일을 복사해 오시면 됩니다.
3. 편리한 SQLite3 Tool 사용하기
Tool은 원하시는 것 아무거나 사용하셔도 되는데요.
SQLite3 를 Tool은 구글에서 검색해 보시면 많이 나온답니다.
http://sqlitebrowser.sourceforge.net/index.html
저 위 사이트의 SQLiteBrowser 라는 프로그램을 받았습니다.
4. SQLiteBrowser 를 사용하여 db 파일 보기
이 프로그램을 사용해서 PC로 가져온 파일을 열면 아래와 같이 보입니다.
DB 파일에 들어간 table 들의 이름이 보입니다.
각 테이블 이름 옆의 확장하는 + 아이콘을 누르면, 각 필드의 정보를 볼 수가 있답니다.
이것은 video 테이블을 열어 본 것이랍니다.
필드의 이름을 확인가능하고,
데이타가 어떤식으로 들어가 있는지 확인이 가능하답니다.
_data 에는 full path가 있고,
_display_name 에는 파일명이 있고,
mine_type 은 파일의 형식이 있고,
....
이렇게 table의 내용과 구조를 보면서 소스를 분석하시면 훨씬 이해가 편하답니다. ^^
감사합니다.
지금 그 작업을 하고 있는데,, 님의 노하우를 얻고 싶네요.
저는 파일을 PC로 파일로 복사를 어떻게 하는지 안됩니다.
adb pull /data/data/com.android.providers.media/databases/external-12e23719.db .
C:\android-sdk-windows>adb pull /data/data/com.android.providers.media/databases/external-1a02300b.db
Android Debug Bridge version 1.0.25
-d - directs command to the only connected USB device
returns an error if more than one USB device is present.
-e - directs command to the only running emulator.
returns an error if more than one emulator is running.
-s <serial number> - directs command to the USB device or emulator with
the given serial number. Overrides ANDROID_SERIAL
envivornment variable.
-p <product name or path> - simple product name like 'sooner', or
a relative/absolute path to a product
out directory like 'out/target/product/sooner'.
If -p is not specified, the ANDROID_PRODUCT_OUT
environment variable is used, which must
be an absolute path. devices
- list all connected devices
connect <host>:<port> - connect to a device via TCP/IP disconnect <host>:<port> - disconnect from a TCP/IP device
device commands:
adb push <local> <remote> - copy file/dir to device
adb pull <remote> <local> - copy file/dir from device
adb sync [ <directory> ] - copy host->device only if changed
(see 'adb help all')
adb shell - run remote shell interactively
adb shell <command> - run remote shell command
adb emu <command> - run emulator console command
adb logcat [ <filter-spec> ] - View device log
adb forward <local> <remote> - forward socket connections
forward specs are one of:
tcp:<port>
localabstract:<unix domain socket name>
localreserved:<unix domain socket name>
localfilesystem:<unix domain socket name>
dev:<character device name>
jdwp:<process pid> (remote only)
adb jdwp - list PIDs of processes hosting a JDWP transport
adb install [-l] [-r] <file> - push this package file to the device and install it
('-l' means forward-lock the app)
('-r' means reinstall the app, keeping its data)
adb uninstall [-k] <package> - remove this app package from the device
('-k' means keep the data and cache directories)
adb bugreport - return all information from the device
that should be included in a bug report.
adb help - show this help message
adb version - show version num
DATAOPTS:
(no option) - don't touch the data partition
-w - wipe the data partition
-d - flash the data partition
scripting:
adb wait-for-device - block until device is online
adb start-server - ensure that there is a server running
adb kill-server - kill the server if it is running
adb get-state - prints: offline | bootloader | device
adb get-serialno - prints: <serial-number>
adb status-window - continuously print device status for a specified device
adb remount - remounts the /system partition on the device read-write
adb reboot [bootloader|recovery] - reboots the device, optionally into the bootloader or recovery program
adb root - restarts the adbd daemon with root permissions
adb usb - restarts the adbd daemon listening on USB adb
tcpip <port> - restarts the adbd daemon listening on TCP on the spec
ified port
networking:
adb ppp <tty> [parameters] - Run PPP over USB.
Note: you should not automatically start a PPP connection.
<tty> refers to the tty for PPP stream. Eg. dev:/dev/omap_csmi_tty1
[parameters] - Eg. defaultroute debug dump local notty usepeerdns
adb sync notes: adb sync [ <directory> ]
<localdir> can be interpreted in several ways:
- If <directory> is not specified, both /system and /data partitions will be updated.
- If it is "system" or "data", only the corresponding partition
is updated.
어떻게 해야 가져 올수 있나여