I have created a database for my application. Now I want to make sure that all the attributes are correct and rows are getting filled properly. Database seems to be in /data folder but this folder seems to be empty. When I try to use sqlite3 to access it (from the command line using adb shell ) I get a not found error. The android phone that I am playing around is a Google Nexus S. Any ideas on how to export it or test that the database is build correctly and used as intended?
Add a comment
|
3 Answers
In the DDMS perspective use the file explorer while an emulator is running. You can explore the folders there. You will find your database in /data/data/your-package-name/databases You can find details about DDMS here
2 Comments
Nivir
Please look at the following link, step by step procedure with images, same as @C.d wrote. weston-fl.com/blog/?p=2812
George
This will only work if your device is rooted - emulators are rooted by default. In many of the devices you will not have access to /data/data to do what you are suggesting.
You might find this question helpful:
How do I backup a database file to the SD card on Android?
@skeniver says:
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "//data//{package name}//databases//{database name}";
String backupDBPath = "{database name}";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
if (currentDB.exists()) {
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
}
}
} catch (Exception e) {
}
with @Jakobud adding that you need to have the
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
in your manifest.
Comments
You will need to either root your phone, or else use the emulator. On normal non-rooted phones, you don't have permission to access private app data like this.
5 Comments
JustCurious
At some point either way I will have to get the tables of the database as I will have to perform a data analysis on them. There should be a way of getting those data. As for now, how can I access those data from emulator?
Graham Borland
See C.d.'s answer for details on how to browse the emulator's filesystem from Eclipse/DDMS.
JustCurious
Thanks! How about when I will have to export it for data analysis? I will need to export many databases then.
Graham Borland
Added link to my answer telling you how to export the data.
kalan nawarathne
Your link just point to your whole web site. Please consider pointing to the article instead of the whole web site.