Accessing the database of one application from another application

I created an application and now I want to copy the database of this 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 a code that copies a database from a given path to an SD card. However, when I initially checked 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?

+4
source share
4 answers

You can use the same database only if you created the working database of the application in specialized content.

You cannot directly access the database from a running application.

But if you create your application database in user content, then with the help of authorities you can directly access the database.

In this case, you do not even need to copy this database.

Send a link for a custom content provider.

+8
source
 No 

you cannot access the database of another application if the application does not provide you with an interface through the ContentProvider.

+3
source

Using DDMS, you can browse your SQLite database, so read the DDMS guide at this link http://www.brighthub.com/mobile/google-android/articles/25023.aspx http://www.edumobile.org/ android / category / android-beginner-tutorials /

+2
source

Read Android Security. Any data stored by the application will be assigned to this application user ID and will not normally be available for other packages.

+2
source

Source: https://habr.com/ru/post/1413926/


All Articles