Android Question Read a database from another app?

welu1805

Active Member
Licensed User
Hi all,

I have 2 apps (e.g. A and B).

In File.DirDefaultExternal of app A is a SQLite database with the table "texte".

From app B I want to open the database from app A and read the table "texte".

Is this possible? In my example in app B I get the error "not found" but with File.Exists I see that path and filename are correct.

Has anyone an idea?

Thanks
Lutz
 

DonManfred

Expert
Licensed User
App B does not have the rights to access files from App A. thats the primary point. It is not possible.

Store the Database on a Path accessible by both. Also note that you should NOT access the database from two apps at the same time. One app in foreground and the other app in background using a service or so. Sqlite is not able to handle this.

Or better; use a jRDC as Database middleware and access the data from both apps from this Database.
In Android you would need to create an ContentProvider in App A and Access this content from App B. But there is no Library to do so at this time i think. Or i do not remember having seen one.

In my wrap for the Whatsappstticker is a ContentProvider working. But it is one specific to some known files in the filesfolder (static files in this case).
If you are interested in reading more about it. Creating a content Provider.
 
Last edited:

DonManfred

Expert
Licensed User

Erel

Administrator
Staff member
Licensed User
Don't use File.DirDefaultExternal. Use RuntimePermissions.GetSafeDirDefaultExternal instead (same path but doesn't require permission*).

This path can be accessed by other apps. They just need to request the write external storage. You can use it to share the database.
The path is specific to each app so you will need to use the path string (Log(File.DirDefaultExternal)).

* - See runtime permissions tutorial
 
Top