1

I am trying to find an andriod's app database when it is connected to my PC. I am pretty sure it is in my internal storage, but I don't even see a file with the app's name. How should I start?

Caspar Geerlings
  • 1,021
  • 2
  • 10
  • 21
Yuxuan Xia
  • 71
  • 1
  • 3

2 Answers2

0

In Android Studio go to View/ Tool Windows/ Device File explorer.

Then you have to look for data/data folder, inside there are the packages of all apps of your phone, you have to look for the name of your apps' package and open the database folder.

Inside you can find your database.

Remember that in order to access this folder your phone must be rooted or you can use a simulator. But there is a trick you can extract the database programmatically if your phone is not rooted.

Like this

dicarlomagnus
  • 576
  • 4
  • 17
  • Thank you for your answer. So the name of my app is Masimo, and I found a package called com.masimo.merlin.consumer inside data/data. I am assuming this is the package I am looking for. However, when I opened the package, it says run-as: Package 'com.masimo.merlin.consumer' is not debuggable. I saw many methods that can copy the original database onto external storage so that we have access to them, but I don't know what the name of the database is without seeing the content of the package. – Yuxuan Xia Nov 13 '18 at 21:21
0

Following method will create a copy of our original database, which we can connect to pc and open. we can also open it with some database applications in mobile itself.

 private void writeToSD() throws IOException {
    String DB_PATH;

    if (Build.VERSION.SDK_INT >= 17) {
        DB_PATH = getFilesDir().getAbsolutePath().replace("files", "databases") + File.separator;
    } else {
        DB_PATH = getFilesDir().getPath() + getPackageName() + "/databases/";
    }
    File sd = Environment.getExternalStorageDirectory();
    if (sd.canWrite()) {
        File currentDB = new File(DB_PATH, "MyLookDBManager");//DATABASE NAME
        File backupDB = new File(sd, "backup_MYAPP.db");// OUTPUT FILE NAME
        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();
        }
    }
}

you have to change backup_MYAPP.db (output file name), MyLookDBManager(database name) according to your app name.

Uma Achanta
  • 3,669
  • 4
  • 22
  • 49
  • 1
    Thank you so much. My ultimate goal is actually to copy the whole database onto SD card. Right now the getFileDir() and getPackageName() raise error saying that cannot resolve method. I am not sure how to proceed. – Yuxuan Xia Nov 13 '18 at 16:13
  • are you using it in fragment or activity? – Uma Achanta Nov 14 '18 at 05:18
  • If you are using it in fragment you have add `getActivity()` beforethose two. ex:`getActivity().getFilesDir()` – Uma Achanta Nov 14 '18 at 05:21