Skip to content

Instantly share code, notes, and snippets.

@bhardwajAbhi
Forked from ChrisRisner/GettingPreference.java
Created September 4, 2023 10:32
Show Gist options
  • Save bhardwajAbhi/4d957a24d4d9baa60700b2769eebbf31 to your computer and use it in GitHub Desktop.
Save bhardwajAbhi/4d957a24d4d9baa60700b2769eebbf31 to your computer and use it in GitHub Desktop.
Sharing Shared Preferences between Android Apps
Context myContext = getApplicationContext().createPackageContext
("com.cr.sharedprefexampleone", Context.MODE_WORLD_WRITEABLE);
SharedPreferences testPrefs = myContext.getSharedPreferences
("sharedprefone", Context.MODE_WORLD_READABLE);
String prefString = testPrefs.getString("time", "Couldn't find");
SharedPreferences prefs = getApplicationContext().
getSharedPreferences("sharedprefone", Context.MODE_WORLD_READABLE);
Editor edit = prefs.edit();
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date(); //
edit.putString("time", dateFormat.format(date));
edit.commit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment