Access Shared preference data from one application to another application

Published Apr 04, 2017

Create Shared preferece data in first application set its mode to MODE_WORLD_READABLE. Here is a following snippet you can find how to create shared preference and store data into it.

mSharedPrefs = getSharedPreferences("Prefs_First", MODE_WORLD_READABLE);
SharedPreferences.Editor editor = mSharedPrefs.edit();
editor.putString("name", etName.getEditableText().toString());
editor.putString("password", etPassword.getEditableText().toString());

In another application you have to access that shared preference get data from this as very simple way. Here is snippet for the same.

Context mContext = createPackageContext("com.kuls.globalsharedpreference_first", CONTEXT_IGNORE_SECURITY);

SharedPreferences firstAppSharedPrefs = mContext.getSharedPreferences("Prefs_First", Context.MODE_WORLD_READABLE);

String strName = firstAppSharedPrefs.getString("name", "");
String strPassword = firstAppSharedPrefs.getString("password", "");
Discover and read more posts from Kuldeep Joshi
get started