Share a piece of data between several Android apps
<p>I am writing an SDK for Android that will be used by many different apps. Each app needs to know if there is a previous installation of another app that uses the SDK; the first one will create a random id (a cookie) and store it, all later apps have to read it and reuse it. Note that the cookie will be created anew for every device.</p>

<p>I have searched for a long time for the answer; please read thoroughly before answering because I have read lots of different StackOverflow answers and have scoured the internet reading random blogs; I have tried a lot of things but none worked (I will save you the links).</p>

<ul>
<li>A ContentProvider is definitely overkill. Also it needs to intrude an app's <code>AndroidManifest.xml</code>, something I am trying to avoid.</li>
<li>Likewise for a service: needs to be defined in the <code>AndroidManifest.xml</code>, which I do not control and do not want to require changes to.</li>
<li>Using external storage would perhaps be an option, but I don't want to require additional permissions.</li>
<li>Using <code>SharedPreferences</code> directly with <code>getSharedPreferences()</code> does not work because apps can only access their own preferences.</li>
<li>I can get a common preferences object using <code>createPackageContext(package, MODE).getSharedPreferences()</code>. This would work beautifully if I had a main package and many clients of the data, but in fact I don't know the package of the app that will be installed first -- it can be any of them. I don't even have a list of package names to search. Passing a package name which has not been installed fails.</li>
<li><p>Following the approach above, I have tried to piggyback on some standard Android app which I can count on, and store my preferences there -- say:</p>

<pre><code>createPackageContext(
    "com.android.browser",
    Context.CONTEXT_RESTRICTED)
    .getSharedPreferences(
        "GLOBAL_PREFS",
        Context.MODE_WORLD_READABLE);
</code></pre>

<p>but it does not work: the error reads</p>

<pre><code>Couldn't create directory for SharedPreferences file
  /data/data/com.android.browser/shared_prefs/GLOBAL_PREFS.xml
</code></pre></li>
</ul>

<p>So, to recap: I need to store a piece of data (a short string) in some standard location, so that any other app can go there and read it if present, and it should work if at all possible without doing any magic in the <code>AndroidManifest.xml</code> or requesting any permissions.</p>

<p>There probably isn't any perfect answer, so perhaps the best solution is to write to external storage; then so be it. To put things into context, apparently it is trivial to do this on iOS using a keychain, designed to store secure data.</p>
