Accessing the database of one application from another application
Asked Answered
H

4

6

I've built an application and now I want to copy the database of that running application using my new backup application. I create my database path by doing DB_PATH + DB_NAME, using the following values:

DB_PATH = "/data/data/iCam.Cam/";
DB_NAME = "testdb.db";

I have code which copies the database from the given path to the SD Card. However, when I initially check the database using the following method, it returns false:

public boolean checkDataBase() {    
    SQLiteDatabase checkDB = null;

    try {
        String myPath = DB_PATH + DB_NAME;
        checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
    } catch (SQLiteException e) {
        e.fillInStackTrace();
        // database does't exist yet.
    }

    if (checkDB != null) {
        checkDB.close();
    }

    return checkDB != null ? true : false;
}

Any suggestions on how to achieve this?

Heterozygous answered 23/5, 2012 at 11:21 Comment(2)
@Rasel's answer is correct. You should use contentProvider from your actual application to share you database control. why do you want to copy it anyway??Osmium
i want to copy it coz my app send database to server but it not currently sending some data that is to be uploaded to web so i need that database to copy to sd card so that i can be sent through mailHeterozygous
E
10

You can use the same database only if you created the running application database in custom content provider.

You cannot directly access the database from running application.

But if you create your running application database in Custom Content Provider then with the help of authorities you can directly access the database.

In this case you don't even need to copy that database.

Refer this link for custom content provider.

Elizaelizabet answered 23/5, 2012 at 11:31 Comment(0)
A
4
No

you can't access the database of other application unless the application give you the interface through the ContentProvider.

Aerolite answered 23/5, 2012 at 11:26 Comment(0)
R
2

Using DDMS you can browse your SQLite DataBase so read the tutorial of DDMS from this link http://www.brighthub.com/mobile/google-android/articles/25023.aspx http://www.edumobile.org/android/category/android-beginner-tutorials/

Ratty answered 23/5, 2012 at 11:25 Comment(1)
i am to give this setup to my remote clientHeterozygous
G
2

Read Android Security. Any data stored by an application will be assigned that application's user ID, and not normally accessible to other packages

Guiltless answered 23/5, 2012 at 11:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.