EDITED读取SharedPreferences:无法从其他应用程序
我有一个应用程序,写入SharedPreferences这样的:
Context otherAppsContext = null;
try {
otherAppsContext = createPackageContext("AfroKeyboard.com.rob", Context.CONTEXT_IGNORE_SECURITY);
} catch (NameNotFoundException e) {
}
SharedPreferences sharedPreferences = otherAppsContext.getSharedPreferences("PREFS_PRIVATE", Context.MODE_WORLD_READABLE);
Editor prefsPrivateEditor = sharedPreferences.edit();
prefsPrivateEditor.putString("layout02", jString);
prefsPrivateEditor.putString("layout02name", "Russian Layout");
prefsPrivateEditor.commit();
,具有由他们
Context otherAppsContext = null;
try {
otherAppsContext = createPackageContext("AfroKeyboard.com.rob", Context.CONTEXT_IGNORE_SECURITY);
} catch (NameNotFoundException e) {
}
SharedPreferences sharedPreferences = otherAppsContext.getSharedPreferences("PREFS_PRIVATE", Context.MODE_WORLD_READABLE);
Log.e("name2" , "name2: "+sharedPreferences.getString("layout02name", ""));
读取另一个应用程序
但它返回空。
您认为可能是什么问题?
谢谢!
myPrefs = otherAppsContext.getSharedPreferences("NAME_OF_SHARED_PREFERENCES", Context.MODE_WORLD_READABLE);
String s = myPrefs.getString("layout02name", ""));
特拉维斯,你有什么问题与我的答案? – 2012-03-29 16:47:23
似乎没有阅读...我应该把什么,而不是PREFS_PRIVATE? – 2012-03-29 17:19:27