1

I have a project that can store data to sqlite database. I want to know how can i access the sqlite database inside on real device using eclipse juno on DDMS?

Bjorn
  • 69,215
  • 39
  • 136
  • 164
JD Jr.
  • 47
  • 1
  • 11
  • 1
    possible duplicate of [How can I backup sqlite file in SD Card programmatically?](http://stackoverflow.com/questions/12489718/how-can-i-backup-sqlite-file-in-sd-card-programmatically) – DCoder Jan 28 '15 at 06:18
  • go to device storage directory, you'll find your database with name DatabaseName.db – Zeeshan Saiyed Jan 28 '15 at 06:25

1 Answers1

0

You don't have permission to open database from real device. You need rooted device to do it. But If you want to check database on real device, you can copy it to external drive and then you can access it.

public static void copyDatabaseToSdCard(Context myContext) {

    try {
        File f1 = new File("/data/data/" + myContext.getPackageName() + "/databases/" + myContext.getResources().getString(R.string.db_name));
        if (f1.exists()) {
            File f2 = new File(Environment.getExternalStorageDirectory().getAbsoluteFile() + "/xyz.db");
            f2.createNewFile();
            InputStream in = new FileInputStream(f1);
            OutputStream out = new FileOutputStream(f2);
            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            in.close();
            out.close();
        }
    } catch (FileNotFoundException ex) {
        System.out.println(ex.getMessage() + "in the specified directory.");
        System.exit(0);
    } catch (IOException e) {
        e.printStackTrace();
        System.out.println(e.getMessage());
    }

}
Karn Shah
  • 501
  • 4
  • 14