0

I want to show sqlite database for that I follow this step. But I'm using my mobile for testing the app. So when I click on DBMS -> file explorer -> data it doesn't open.

Community
  • 1
  • 1
Bhavin Patel
  • 872
  • 13
  • 30

1 Answers1

1

If the device is not rooted then we can't access the sqlite database from device in DDMS mode but you can able to copy to SD card by the following code.

try
        {
            File sd = Environment.getExternalStorageDirectory();
            File data = Environment.getDataDirectory();

            if (sd.canWrite())
            {
                String currentDBPath = "/data/" + getPackageName() + "/databases/yourdatabasename";
                String backupDBPath = "backupname.db";
                File currentDB = new File(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)
        {

        }
Kumar M
  • 994
  • 6
  • 21