Hi all,
If i create manually preference xml file and try to push in device i can able to read the file contains.
But same thing if i create prefrence xml file from code and trying to read it from code it throws following warning and value read got wrong.
WARN/ApplicationContext(5323): Attempt to read preferences file /data/data/com.xyz/shared_prefs/Custom.xml without permission .
For writing the code is,
SharedPreferences sharedCustom = this.getSharedPreferences("Custom", Context.MODE_WORLD_WRITEABLE);
SharedPreferences.Editor editor = sharedCustom.edit();
editor.putInt("storedInt", 5); // value to store
editor.commit();
For reading them,
con = createPackageContext("com.hcl",
Context.CONTEXT_IGNORE_SECURITY|Context.CONTEXT_INCLUDE_CODE | Context.MODE_WORLD_WRITEABLE);
SharedPreferences sPreferences=con.getSharedPreferences("Custom", Context.MODE_WORLD_WRITEABLE);
int value = sPreferences.getInt("storedInt",0);
Regards,
Swapnil
Thursday, September 23, 2010
Tuesday, September 21, 2010
Shared Preferences Across Application
Hi all,
I have some prefernces created using xml in one application . i want to access it in other application. How i can achive this?
I am using ListPrefernces . I tried to use following code in my outside application to read the prefernces but its not getting the values,
myContext = createPackageContext("com.xyz",Context.MODE_WORLD_WRITEABLE);
SharedPreferences testPrefs = myContext.getSharedPreferences("com.hcl_Kodakpreferences", Context.MODE_WORLD_READABLE);
String computerName = testPrefs.getString("firstKey", "defaultValue");
I have some prefernces created using xml in one application . i want to access it in other application. How i can achive this?
I am using ListPrefernces . I tried to use following code in my outside application to read the prefernces but its not getting the values,
myContext = createPackageContext("com.xyz",Context.MODE_WORLD_WRITEABLE);
SharedPreferences testPrefs = myContext.getSharedPreferences("com.hcl_Kodakpreferences", Context.MODE_WORLD_READABLE);
String computerName = testPrefs.getString("firstKey", "defaultValue");
Subscribe to:
Comments (Atom)