1

I have a set of 4 applications, all of them need a general database. The user can use any app first and that app creates the sqlite database.

I think I can create the database in a specific folder using a full path in the SQLiteOpenHelper, maybe I can create the database in a specific path and make all the apps use this database, but data would lose security.

I checked some answers where it is recommended to use a ContentProvider or sharedUserId, but the examples are for scenarios where an app want to share its data, in this case is a common database for all apps, How can I use a ContentProvider in this scenario?

What would be a good way to achieve that?

Allan Pereira
  • 2,572
  • 4
  • 21
  • 28
joel
  • 59
  • 1
  • 2
  • We have build a propietary system that has a lot of apps accessing the same database, and we did it with `ContentProvider`. I think that's the way to go. The examples for `ContentProvider` are the same: an app sharing its data is the same as a database for all apps. – m0skit0 Apr 27 '16 at 16:13
  • Thanks for the comments, @m0skit0 your case is really similar, It sounds like ContentProvider is the way to go, but I don't know what app would create the database,the idea was "the first app the user opens creates the database", maybe I need that only one specific app creates the database and guiding the users to open that one before they can use all the apps. – joel Apr 27 '16 at 16:33
  • Ok, I see. I think the way to go is to include the `ContentProvider` on all your apps. When an app runs, it checks if the `ContentProvider` exists. If it does, it just uses that one. If not, it sets it up and exposes it. The only problem I can think of using this approach is that you maybe wouldn't be able to declare the `ContentProvider` in the manifest. In our case since we own the system, we have a dedicated `Service` that has the `ContentProvider`, and all other apps depend on this `Service`. – m0skit0 Apr 27 '16 at 16:39
  • I see, I would try something like that. Thanks for the comment. – joel Apr 27 '16 at 17:03

1 Answers1

0

The best way is using a ContentProvider in one of your apps and using the URIs in your other apps. As for today, that's the only way you can "share" a database in several apps.

Isaac Urbina
  • 1,295
  • 11
  • 21