I'm trying this with my Nexus One. I have the android SDK and have used the command adb pull /data/data/com.myapp.android/databases C:\pulls but all I get is pull: building file list... 0 files pulled. 0 files skipped. Also, it seems no matter how much data I add to the tutorial NotePad app I installed, the data size for the app (as shown in Settings) never exceeds 8KB. How is this possible? Is there some other place where databases are stored? When I use the File Explorer view (that's part of ADT) in Eclipse, I see there's nothing in /data. To add a twist, I have no trouble pulling any other files from the device. It's just databases I have trouble with. Am I missing something? Thanks much.
Accessing internal storage is not possible unless your phone is rooted. One simple way is to use the emulator, and then you can get at the files. For getting a database off the device I wrote a little utility and put in some debug UI for it:
private void backupDb() throws IOException {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "/data/com.yourcompany.yourapp/databases/yourapp.db";
String backupDBPath = "/yourapp_logs/yourapp.db";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
if (backupDB.exists())
backupDB.delete();
if (currentDB.exists()) {
makeLogsFolder();
copy(currentDB, backupDB);
}
dbFilePath = backupDB.getAbsolutePath();
}
}
private void makeLogsFolder() {
try {
File sdFolder = new File(Environment.getExternalStorageDirectory(), "/yourapp_logs/");
sdFolder.mkdirs();
}
catch (Exception e) {}
}
private void copy(File from, File to) throws FileNotFoundException, IOException {
FileChannel src = null;
FileChannel dst = null;
try {
src = new FileInputStream(from).getChannel();
dst = new FileOutputStream(to).getChannel();
dst.transferFrom(src, 0, src.size());
}
finally {
if (src != null)
src.close();
if (dst != null)
dst.close();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With