我有一个设置应用程序,我必须从中检索其他应用程序首选项,但我没有其中的键的详细信息,如何检索该首选项中的所有可用键和值?
谢谢,
斯瓦蒂
好的!在应用程序 1(包名称为“com.sharedpref1”)中使用此代码来存储具有共享首选项的数据。
SharedPreferences prefs = getSharedPreferences("demopref",
Context.MODE_WORLD_READABLE);
SharedPreferences.Editor editor = prefs.edit();
editor.putString("demostring", strShareValue);
editor.commit();
在应用程序 2 中使用此代码从应用程序 1 中的共享首选项获取数据。我们可以获取它,因为我们在应用程序 1 中使用了 MODE_WORLD_READABLE:
try {
con = createPackageContext("com.sharedpref1", 0);
SharedPreferences pref = con.getSharedPreferences(
"demopref", Context.MODE_PRIVATE);
String data = pref.getString("demostring", "No Value");
displaySharedValue.setText(data);
} catch (NameNotFoundException e) {
Log.e("Not data shared", e.toString());
}
更多信息请访问此网址:http://androiddhamu.blogspot.in/2012/03/share-data-across-application-in.html http://androiddhamu.blogspot.in/2012/03/share-data-across-application-in.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)