what if I have a Code like this:
SharedPreferences prefs=getSharedPreferences("myPrefs",0);
And now I am so dumb and set it to (lets say the first release of my app had the above code....now several months later I release it with the code change below on the store)
SharedPreferences prefs=getSharedPreferences("myPrefs",1);
So I change the acces of it from 0(private) to 1(world readable) or 2 (world writeable)
Are there now two Preferences? So I have to sets of Preferences with different Key-Value pairs and different read/write visibilities in them but all have the same name/key?!
Thank you
since AFAIK android allocate a linux user to each app to acheive some kind of sandbox environment, my guess is that you only change the underline file linux premissions from private (access to the app's user only) to readable by all other programs, if they can access it they would be able to read it.
Related
I want to declare a key inside my code and publish app with this key, then when app is published I want to be able change that key.
But my aim is to have one app and customize it for different users.
Do you have any offer?
May you explain a scenario?
Note : better to say that I want to separate each user's version by a unique key;
1- I can do this : I can change the variable value, publish app and send for user. But I wand to change key value in a published app, not from source code and re-publish.
2- using external file, shared-preference, and other ways, user will loose his version when uninstall app, and I want to avoid it.
You can just declare key in String.xml,
if you want to changes key run time, you have to go with sharedpreference in android, this store data in xml format.
more help visit this link, SharedPreferences : no saving to device, change it inside a packed app!
also this will help you Storage option in android : no storage, it is change value in a compiled app!
My app can backup and restore all my data, including the shared preference values. However, when I get all my shared preferences, I also get two with the names "drt" and "drt_ts". I've discovered these are from Admob.
Is there any way for me to iterate through the preferences and get ONLY the one ones my own app has created? There doesn't seem to be any concept of owner or creator.
If you want to have your own SharedPreferences, that is separate from the Default one for your app you should consider using SharedPreferences.getSharedPreferences(String name, int mode). The BackupHandler has support for multiple SharedPreferences files.
If you want to have AdMob save their preferences somewhere else then that is a different question, maybe it is possible, check with the documentation for AdMob?
http://developer.android.com/reference/android/content/Context.html#getSharedPreferences%28java.lang.String,%20int%29
I'm working on a monitoring system that can accommodate many Sites. A Site is defined by an ID and Password, as well as some boolean options.
It's fairly easy to manage one site with the settings. I can use PreferenceManager to get the Default Shared Preferences for a Context, and each setting is identified by a string Key. But is it possible to have multiple sets of settings? E.g. for each Site to have its own set of settings?
If not, should I bypass the PreferencesManager and store settings for each site in a Sqlite database?
You can use Properties and create activity manually
I've nearly finished writing a game for the Android market. I have a full version and a free version with half the levels. I’ve read of a lot of people in similar situation with the following problem but can’t find a satisfactory solution:
My apps are separate but I want them to share data. At least I want the full version to be able to read the free version’s progress data. If a user finishes the free version, then installs the full, it needs to access the progress info because the first stage of the game is identical to the free version and the progress should be shared/mapped.
From what I have read the best way to save game progress is using SharedPreferences, which is what I’m doing and it’s working perfectly.
On searching for ways to share data I read that the best thing to do is to define the same android:sharedUserId in both AndroidManifest.xml files to be the same value and to ensure both apps are signed with the same key:
What is sharedUserId in Android, and how is it used?
multiple apps, sharing same data directory
I’ve done this and checked it’s working by using ApplicationInfo to see both app’s uids, which are the same. However, I was then expecting to be able to read and write to SharedPrefs from both apps (running at different times) and to be reading/writing the same data. But alas no. If this does not make the apps share the same SharedPreferences, then what data are they sharing by specifying the same sharedUserId?
After some more digging some people seem to be saying I need to access the other app’s context first:
http://thedevelopersinfo.com/2009/11/25/getting-sharedpreferences-from-other-application-in-android/
Can't read SharedPreferences fron another application
So if I want App2 to access App1's data, this gives me the following code in App2’s Activity:
Context otherAppsContext = null;
try {
otherAppsContext = createPackageContext("com.example.app1package",0);
} catch (NameNotFoundException e) {
}
SharedPreferences sharedPrefs = otherAppsContext.getSharedPreferences("TestShareData",Context.MODE_PRIVATE);
But when I ask sharedPrefs for data it still just gives me data from the current app (App2 instead of App1).
Inspecting the otherAppsContext variable I’m not sure what it’s giving me. It has an mBasePackageName property which is the package name of App2 (wrong). But it also has an mPackageInfo property which appears to contain data about App1.
I just don’t know if I’m doing things the right way but am missing something or if this isn't the way to go at all. I just want to link my 2 apps in such a way that one can read the other’s SharedPrefs. How do most full versions of apps link to the free one's data?
Any help would be greatly appreciated!
Sure this happens a lot but think I may have solved my own problem.
Both of my apps (full and free versions) are writing to sharedPrefs under the same name:
SharedPreferences settings = getSharedPreferences( PREFS_NAME, 0 );
Where PREFS_NAME is the same for both apps. When I ask for App1's Context from App2 it gives me a Context but it seems it's a Context that can access both Apps' data?
To explain when I get a Context for App1, from App2 and ask for SharedPreferences giving the name PREFS_NAME, I get the SharedPrefs from App2 instead. But I tried changing the SharedPrefs name for App1 and then accessing that from the context in App2 and suddenly it picks up App1's data.
I don't really know what I'm getting back from the createPackageContext call, it seems to be a handle to both sets of data. But I think I can just make my apps use different names for the SharedPrefs and have the full app just search for the free app's data if it needs to.
If I store some user settings and information in shared preferences in my android apps, and then I update the app in the Market, will those settings be erased when the app updates?
No, the Shared Preferences will remain.
To make the answer simple: NO in normal circumstances.
The update process only replaces the apk file(and so what is in it for
example drawables,...) and does not alter databases,sharedpreferences
and any other files that generated in run time(probably in this
case,new App is installed with the UID that is equal to UID of
previous App).
But following this thread it seems that there are cases when data could be lost. Like changing Copy PROTECTION FROM ON to OFF OR OFF to ON.
Quoting the answer:
It turns out when we posted the update copy protection was turned off,
but for our initial release it was turned on. Which caused all our
shared preferences to get lost, we could no longer create private data
files, and the game started randomly crashing.