Ad

How To Allow Two Or More React Native Apps To Share Data With Each Other?

I am working on a POC where I want to share data between two or more apps on the same device. I have read about Shared Preferences for Android but the article said that Apps can only read data stored by them or they can store data as global, in which case, all apps on the OS can read the stored data. Similarly, I am thinking of using Keychain for iOS.

The problem in short: I want to be able to share a piece of data with other apps on the device.

Apart from shared preferences and keychain, is there any other way to accomplish this?

Also, all the apps will be written using React Native.

Ad

Answer

I don't know how you're going to implement this in iOS/ReactNative, but in Android, to share data between apps, you'll need to use ContentProvider

A content provider manages access to a central repository of data. A provider is part of an Android application, which often provides its own UI for working with the data. However, content providers are primarily intended to be used by other applications, which access the provider using a provider client object. Together, providers and provider clients offer a consistent, standard interface to data that also handles inter-process communication and secure data access.

Typically you work with content providers in one of two scenarios; you may want to implement code to access an existing content provider in another application, or you may want to create a new content provider in your application to share data with other applications. This topic covers the basics of working with existing content providers. To learn more about implementing content providers in your own applications, see Creating a content provider.

You may find more information here, and a very good example from here

Ad
source: stackoverflow.com
Ad