2

Possible Duplicate:
Share SQLite database between 2 android apps?

I'm trying to work with SQLite databases, open it,retrieve data from it,insert data, I did thit perfectly, but with sqlite databases I created in the same application, but I'm trying to do so with other databases created in other applications.

I tried to open the database like this:

String DB_PATH= "/data/data/my.sqlitemanager/databases/";
String DB_NAME = "commments";
SQLiteDatabase database = SQLiteDatabase.openDatabase(DB_PATH + DB_NAME, null, SQLiteDatabase.OPEN_READONLY);

But it didn't work. How can I do this?

Community
  • 1
  • 1
user1753461
  • 45
  • 2
  • 4
  • You can share databases with shared user ids: http://stackoverflow.com/questions/7053809/share-sqlite-database-between-2-android-apps – mjn Oct 17 '12 at 15:07

3 Answers3

4

One does not simply open the database of another application. ;)

Seriously, for obvious security reasons (and other resource reasons), you can't do that by default. You can though expose the data from one application to other applications if you EXPLICITLY WANT to. This is done by either: implementing a ContentProvider, OR specifically running your two applications with the same userid/permissions.

The more typical approach, if you want any external application to have access to your data, would be to use a ContentProvider.

http://developer.android.com/guide/topics/providers/content-providers.html

The more advanced approach, and the one that you want to use if you control BOTH of the "two apps" that need to share the data, and you want to DISALLOW any other apps from accessing your data, would be to specify the userid and process. Once that is in place you then can share the data directly.

http://developer.android.com/guide/topics/manifest/application-element.html#proc

Charlie Collins
  • 8,806
  • 4
  • 32
  • 41
  • Thanks a lot for your fast reply. Yes I know that it has a security issue,but I'm trying to access a database which I made in another application,actually I just wanted to make a sqlite manager api, that I can pass the path of the database and the database name to, and it will simply open it and work with it. – user1753461 Oct 17 '12 at 16:03
1

By default Sqlite db is created in private folder of each project, which stays hidden for other project. However you can save your Sqlite database in SD-card, so it will be open for all the other project.

Is it possible to copy database file to SD card?

Community
  • 1
  • 1
Lucifer
  • 29,392
  • 25
  • 90
  • 143
-2

The database is stored in a private directory for each application. Sometimes it's even crypted. Maybe try with super-user permissions.

Stephane Mathis
  • 6,542
  • 6
  • 43
  • 69