I have 4-5 different apps and I want to keep their settings parameters common. I want to do it through sharedpref.
Please suggest how to share sharedpref among different apps without making it public for all app.
I have 4-5 different apps and I want to keep their settings parameters common. I want to do it through sharedpref.
Please suggest how to share sharedpref among different apps without making it public for all app.
using following function:
getSharedPreference(String name, int mode)
retrieves and holds content of file path with particular name.
MODE_PRIVATE: File creation mode: the default mode, where the created file can only be accessed by the calling application (or all applications sharing the same user ID).
MODE_WORLD_READABLE: File creation mode: allow all other applications to have read access to the created file.
MODE_WORLD_WRITEABLE : File creation mode: allow all other applications to have write access to the created file.
To access World Readable/Writeable from different app:
Context myContext = createPackageContext("com.example.app",
Context.MODE_WORLD_READABLE); // where com.example.app is the app containing the preferences
SharedPreferences testPrefs = myContext.getSharedPreferences
("test_prefs", Context.MODE_WORLD_READABLE); //test_prefs is the name in getSharePreference's argument
You could create a service that will be used by those applications, it will be managing your preferences. For service you can specify which applications can use it.
Use same key to read and write shared preference in all your apps you will get the same result as you get in app1 and in app2 ...