Sharing data between 2 Android applications

Viewed 766

I have gone through a lot of similar answers, but since a lot of things have changed recently, I wanted to ask it again.

I have an application A that stores data in Shared Preferences. I want application B to be able to access the data stored in the Shared Preferences by application A.

Findings so far -

  • We can't use WORLD_READABLE for Shared Preferences, since it has been deprecated.
  • We can't use sharedUserId to share data since it has been deprecated.
  • I also read that apps signed with the same key can access each other's code and data. But can we access the data just by doing that? (Or do we need to do something else also along with the signing process?). If yes, how?

One of the solutions is to share the data using Content Providers (data source being the Shared Preferences). Are there any other ways to share the data as well?

1 Answers

I also read that apps signed with the same key can access each other's code and data

Only via sharedUserId.

Are there any other ways to share the data as well?

You could:

  • Have one app expose a service that the other app starts and passes the data via Intent extras
  • Have one app expose a service that the other app binds to and passes the data via AIDL parameters
  • Have one app send an explicit broadcast Intent to the other app with the data included in Intent extras
  • Have one app start an activity in the other app with the data included in Intent extras

Those options, as with the ContentProvider solution, can be secured by Android's permission system. If you carefully set up a custom permission, with a protectionLevel of signature, those apps will be able to communicate with each other, but other apps will not be able to hack into those communication channels.

And, of course, another option is to just have one app.

Related