Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing the database of one application from another application

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?

like image 767
Trikaldarshiii Avatar asked May 23 '12 11:05

Trikaldarshiii


People also ask

Can an app access data from another app?

Just as an app can send data to other apps, it can also receive data from other apps as well. Think about how users interact with your application and what data types you want to receive from other applications.

How can we supply data from one application to another application?

To move data from a field in an application to another field in a different application, you can use crossover domains. You can transfer data from a field in one application to a field in another application using crossover domains.

How do applications interact with databases?

Instead, mobile apps use databases as buffers to collect and transfer data to outside servers whenever they can, but have the data readily available for the user. Local databases allow apps to delay outside communication to off-peak hours.


3 Answers

No

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

like image 41
Rasel Avatar answered Oct 21 '22 23:10

Rasel


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.

like image 79
Kri Avatar answered Oct 21 '22 22:10

Kri


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/

like image 2
Thiru VT Avatar answered Oct 21 '22 23:10

Thiru VT