subbu
subbu

Reputation: 146

Database location in android

In my application i have one database,i want to view that database,i followed the following steps:

data > data > your-package-name >(After this it shows two folders,i cant see anyoption for database) databases > your-database-file.

But i cant see the database file.It shows two folders inside my package.Anybody please help me.

Upvotes: 1

Views: 250

Answers (2)

Omid Nazifi
Omid Nazifi

Reputation: 5234

Then following this path, you should see two file without extension. but you can not see content of DB.

If you wanna see it, you should push then import an other SQLite Manager(such as Firefox add-on). Maybe you don't be able to create database, If you can't see it.


Update: For Insert, Delete or get DB in Emulator, you should install Android DDMS(in Eclips help menu->install software) and select in order Push, Delete and Pull icons.

enter image description here

Upvotes: 1

Barak
Barak

Reputation: 16393

You cannot access files on your device in the data directory unless you have rooted your phone (it's a security precaution).

You have a few choices:

1) Run your app in the emulator and pull the database form there using the DDMS

2) Root your phone

3) Put a method in your app to copy your database to a place that you can access outside of the app (such as your SD card).

Simple code to copy to the SD card:

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

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

        File data = Environment.getDataDirectory();
        File inputFile = new File(data,
                "data/your.package.name/databases/yourdb.sqlite");
        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");
    }
}

Upvotes: 1

Related Questions