Access Shared preference data from one application to another application

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());
editor.commit();

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", "");

Hope this could help you for any same concern.

You may also like

Leave a Reply