0

I want to share the data between two android apps :

One way is use external storage : - SD card or Internally provided storage to store the public files and share across the applications

Second way is use ContentProvider (used for large structured storage) : I was referening to the answer : https://stackoverflow.com/a/9602828 ,

My question is :

Can we access shared preference file from another application context ?

and can we store the shared preferences to external storage ?

Community
  • 1
  • 1
user2618875
  • 889
  • 2
  • 11
  • 23
  • Shared preferences can be private or shared, so **yes** I'm guessing you can access the file from another application if it is shared. [Refer here for more info](http://developer.android.com/training/basics/data-storage/shared-preferences.html) – Sbonelo May 07 '15 at 10:43
  • @YourJavaMinion thanks, but I am more interested into - can we store the shared preferences to external storage ? – user2618875 May 07 '15 at 14:46

1 Answers1

0

Yes, you can access shared preference through following code if your preference is WORLD_READABLE-

Context mContext = createPackageContext("com.example.yourpackage", 
Context.MODE_WORLD_WRITEABLE);
SharedPreferences sharedPreference = mContext.getSharedPreferences 
("Preference_Name", Context.MODE_WORLD_READABLE); 
Mohit Rajput
  • 439
  • 3
  • 18
  • thanks, but I am more interested into - can we store the shared preferences to external storage ? – user2618875 May 07 '15 at 14:47
  • You can write file from sharedPreference content into sdcard but there is no method provided by SharedPreference to store it externally – Mohit Rajput May 07 '15 at 14:53
  • To store it in file, you can get example here- http://stackoverflow.com/questions/10864462/how-can-i-backup-sharedpreferences-to-sd-card – Mohit Rajput May 07 '15 at 14:55