Sharing Private App Data in Android

Just a quick post, because this is something that wasn’t obvious. It’s quite common to have multiple versions of an app, usually a paid version and a free version. In order to make the transition from the free to the paid version as easy as possible, you want to have the data shared between the apps.

The first thing you need to do is declare the same ‘sharedUserId‘ in the app manifest for both apps. They also both need to be signed using the same key – but you’ll probably be using the same key anyway. You need to set the key before publishing, otherwise you can have problems.

However, even doing so, you won’t see the same data. Whichever app is the ‘child’ will need to use Context.createPackageContext() with the package name for the ‘parent’. Using this Context, the child can then read and write files as if it were the parent.