0

A client of ours is having problems with his Android app. We determined it is a data issue. Therefore we need to make a copy of the sqllite database on his phone and paste that databaes into our test phones so that we can see his data. Not sure if this is possible.

I tried to look through some documentation but did not find anything.

user2980837
  • 49
  • 1
  • 3

2 Answers2

0

You will have to upgrade just client's application with new verison which will have code provided here

try {
    File sd = Environment.getExternalStorageDirectory();
    File data = Environment.getDataDirectory();
    if (sd.canWrite()) {
        String currentDBPath = "data/"+sPackageName+"/databases/"+sDBName;
        String backupDBPath = "/.appname-external-data-cache/"+sDBName; //"{database name}";
        File dir = new File(sd,backupDBPath.replace(sDBName,""));
        if(dir.mkdir()) {

        }
        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) {

}
Amrut
  • 543
  • 4
  • 8
0

If the device is rooted, you can just copy the file from the device (usually, but not always, found at /data/data/packagename/databases).

Otherwise you will need to add code to the app to copy the file out from the apps private storage to somewhere public like the SD card. You can get at the path to your database with the method:

 getDatabasePath(your_database_name).

If you are unable to change the app's code to do that then you are stuck since no other app has permission to access the app's private storage (unless the device is rooted). When it comes to pasting the database into your test phones, do the reverse - copy the file to your SD card and have a process in the app that copies from the SD card back to 'getDatabasePath(your_database_name)'. Fyi, there are many tools available to browse the SQLite database on a PC, assuming you can get it off the device.

NigelK
  • 8,255
  • 2
  • 30
  • 28