Question

I want to get the database of my app. Usually I go to the "data" folder on my phone trought DDMS file explore, export my db file on computer and open it via SQLiteManager plugin for FF. But on HTC one X 'data' folder is empty and I can't find where my app is installed.

Could you please give me an advice or solution where I can find it?

Was it helpful?

Solution

If you are using an actual device, you will not be able to see or access it from outside unless you root your phone.

If you are using the emulator, the DDMS view will let you navigate to it and pull it from there.

Or, you could have an issue with creating your DB. Without seeing your code we cannot tell.

If you want to get the file off of a real device, you'll need to implement a method to copy it from your data directory to someplace where you do have access (such as your SD card). This would do the trick:

public void backup() {
    try {
        File sdcard = Environment.getExternalStorageDirectory();
        File outputFile = new File(sdcard,
                "YourDB.bak");

        if (!outputFile.exists()) 
             outputFile.createNewFile(); 

        File data = Environment.getDataDirectory();
        File inputFile = new File(data, "data/your.package.name/databases/yourDB");
        InputStream input = new FileInputStream(inputFile);
        OutputStream output = new FileOutputStream(outputFile);
        byte[] buffer = new byte[1024];
        int length;
        while ((length = input.read(buffer)) > 0) {
            output.write(buffer, 0, length);
        }
        output.flush();
        output.close();
        input.close();
    } catch (IOException e) {
        e.printStackTrace();
        throw new Error("Copying Failed");
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top