我正在尝试通过另一个应用程序编辑一个应用程序的 SharedPreferences
,我的代码是这样的
try {
Context plutoContext = getApplicationContext().createPackageContext("me.test",Context.MODE_WORLD_WRITEABLE);
SharedPreferences plutoPreferences = PreferenceManager.getDefaultSharedPreferences(plutoContext);
Editor plutoPrefEditor = plutoPreferences.edit();
plutoPrefEditor.putString("country", "India");
plutoPrefEditor.commit();
}
我遇到了一个错误
E/SharedPreferencesImpl(304):无法为 SharedPreferences 文件创建目录/data/data/me.test/shared_prefs/me.test_preferences.xml
me.test
是我的另一个项目
在 me.test proj 中,我可以毫不费力地编辑和检索 SharedPreferences
我正在 Nexus S android 4.0.4 (Samsung) 上测试它,谁能帮助我
最佳答案
您需要在 AndroidManifest.xml 中添加权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
我和你有同样的问题,我用上面的方案解决了。
关于安卓 : Couldn't create directory for SharedPreferences file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12071679/