I'm developing a library which can be used in multiple applications. The library contains a PreferenceScreen to set certain settings, which often only need to be set once.
I want to make sure the settings are shared (and able to be edited) across applications using my library and for that, I think I should set the SharedPreferences to world writable.
However PreferenceScreen seems to use the default shared preferences and although the packagename will be the same across, the mode is set to private.
How can I set the share mode for PreferenceScreen to world writable?
Related
I want to create a preference set which the user will not easily be able to delete/clean...
the idea i got is to create the persistence files in the public folder as and hidden folder (this way the files wont be deleted on unnistall or if the user asks for clean apps data)
my questions:
1- does anyone knows a better way? is it possible to do that using the apps private folder and somehow tag the files for no deletion?
2- is possible to use native android preferences framework and specify another file to store the properties? how?
3- does anyone know a good, SMALL and simple to use API for persistent properties similar to androids default?
Usage of Shared Preferences in android library projects is allowed?I am trying to work on rating bar but i am not sure whether i can use Shared preferences to write that.
If you have a Context, supplied to you by the app that is using your library, you can use SharedPreferences.
However, you need to be a bit careful to ensure that you do not accidentally try using the same keys as the app might use. You might consider using a unique SharedPreferences file, rather than getDefaultSharedPreferences().
I am using RoboGuice in my application, and i've grown a custom to creating multiple shared preferences files so that each file plays its own role, and contains only small number of keys
however, ever since i started using RoboGuice, it injects my sharedPreferences objects with a single default file.
Is it possible to somehow direct roboguice into creating multiple files ?
Haven't use RoboGuice forever, but back in a days this was the way:
https://code.google.com/p/roboguice/wiki/ProvidedInjections#Shared_Preferences
I'm using PreferenceActivity to let Android handle some persistent key/value pairs for my app.
According to the Android Preference docs :
Note that saved preferences are accessible only to the application that created them.
However, when further researching the security and permissions aspect of preferences, I come across questions like this one:
Android: Retrieving shared preferences of other application
where some users are saying that preferences may be made world readable and world writeable and that they are successfully able to access them across applications.
So my question is:
Are preferences inalienably inaccessible across applications or do I have to take precautions to make them so?
Note: I'm am not trying to use preferences to share data among apps. Quite the opposite - I want to know that any preferences my users set are secure from inspection/alteration by other apps.
From the above answers and comments, it looks to me like the android developer docs on this subject are a bit misleading.
I even found another place where the developer docs state explicitly that settings are not accessible across apps:
(Note that it is not possible to share settings data across application packages -- for that you will need a content provider.)
Reference to the above quote it here: http://developer.android.com/reference/android/app/Activity.html#SavingPersistentState
But the responses from #shruti and #raman-bhatia (thanks guys!) both support the fact that settings can be configured to be shareable across apps, as does the SO query I referenced in the question.
The clincher was finding this SO query: Difference between getDefaultSharedPreferences and getSharedPreferences which shows how it the default shared preferences file is initially configured as private.
Thanks to all. The answer is that the docs are misleading in that preferences can be coerced to being shareable across apps, but that PreferenceActivity will by default create a secure shared preferences file visible only to the components of the app from which originated.
There are modes associated with the shared preferences that you get to define when you create them.
For example, you can make them as "World Readable" or "World Writable" if you want the rest of the applications on your device to be aware of them.
You can thus use your own flags to adjust the transparency of the shared preferences that you create
I just have some basic questions about the way shared preferences work with Android:
1) Are the preference files part of the application itself, or are they stored elsewhere on the user's phone?
2) If I have created and modified preference files in the course of testing my app, will those preferences be the default settings for users, or do the users start with a clean slate?
1) The preferences are stored on the user's phone, of course.
2) If you want defaults, you need to program them yourself, just setting the preferences in your emulator is not going to affect anybody installing your application.