Reputation: 1003
i've read that shared preferences can be retrieved from outside my application . this code did not work:
try
{
myContext = createPackageContext("com.intervigil.micdroid", Context.MODE_WORLD_WRITEABLE); // where com.example is the owning app containing the preferences
SharedPreferences testPrefs = myContext.getSharedPreferences("test_prefs", Context.MODE_WORLD_READABLE);
Map<String, ?> items = testPrefs.getAll();
nbenroullement= (Integer) items.get("enroullement");
System.out.println("*********************" + nbenroullement);
}
catch (NameNotFoundException e)
{
e.printStackTrace();
}
Please can any one help me . Thank you
Upvotes: 1
Views: 95
Reputation: 1003
Finaly i get the solution in this tutorial I hope that i help you http://androiddhamu.blogspot.in/2012/03/share-data-across-application-in.html
Upvotes: 1
Reputation: 2671
That's probably because you aren't itereting the Maps items
.
So, try to do something like that :
Map<String, ?> items = testPrefs .getAll();
for(String s : items.keySet()){
String value = items.get(s).toString()); //this is the key of preferences
}
Once you retrieve the key (enroullement, I presume) you got to use it like this :
enroullement = Integer.valueOf(prefs.getString("enroullement", "0")); //0 is a default value
Hope it helps.
Upvotes: 0