Retreiving Database from phone/device

I am working on the SQLiteDatabase application on Android that records the user's input as for my survey. Basically, thinking about using the tablet/mobile phone for survey rather than a traditional paper format.

There are 2 main reasons of doing my survey on mobile devices: 1) Save papers - I am not sure how many I need to print in order to collect the information. It also tends to print more than it is necessary.

2) Save time - After collecting data in the paper, I need to record it into digital format, so that I can do the analysis and make presentation based on these data. With the SQLiteDatabase on mobile phone, it is as good as registered on the fly and makes things better and easier to manage.

So, I wrote my application on the eclipse environment and tested on the emulator that is provided in the Android SDK. It works perfect as I test it on the emulator. The data are recorded perfectly on the SQLiteDatabase. Everything went smoothly.

So I copy the APK file into my device and install it. The UI is perfect and there is no error or ugly formatting issues at all. I go through the UI form and inputted all the data for a test. The data are perfectly recorded to the SQLiteDatabase. Now, it's time to retrieve these data for better usage and here comes the problem.

I used a third-party explorer application (It is called ASTRO) to browse my SQLiteDatabase. I have no access to Data/Data//Database at all. It is all restricted by its permission to access it. I even do not have the permission to view it. Some people on the internet suggests to root your device (for those, who are not what root is, it is the super-user access level that can write, edit, read, execute to any files or directories).

So is it end of the road if you do not want to root your device? Nope. I looked for some solutions that could be available for people like me. There are a solution that I found interesting.

Modify your androidManifest file to include the "debuggable = true" option. With this option now, I can use the ADB (you need Android SDK installed in your computer) console to go into the /Data/Data directory with "run-as" command. This is how it looks like:

$run-as ls -l /Data/Data//Database

ls -l is the Linux command for list all the files with some options. So with this debuggable option in Manifest file, you can view it. But wait, can u retrieve it? The answer is NO. I tried

$run-as adb-pull /Data/Data//Database/

I get "permission denied". I can list the application, but again, not allowed to read/write. I tried many methods to root it as I thought it is a last choice for me. I tried and guaranteed that rooting is not 100% successful. Not every device is able to root it. I tried 3 solutions that people shared. None works out for me.

Alright, now this is how i make it to walk around. I make the codes to create a copy of database to SD External card whenever the user has submitted the form. I know it is a bit redundant, but it is the only way for me to walk around from restriction on permission that does not require to root the device. Below is the codes [ Just remember to include use-permission for WRITE_EXTERNAL_STORAGE in your Manifest file ]:


    try {
        File sd = Environment.getExternalStorageDirectory();



        File data = Environment.getDataDirectory();


        if (sd.canWrite()) {

            String currentDBPath = "\\data\\{package name}\\databases\\{database name}";

            String backupDBPath = "{database name}";
            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) {

    }