安卓 : Couldn't create directory for SharedPreferences file

标签 android android-layout android-intent

我正在尝试通过另一个应用程序编辑一个应用程序的 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/

相关文章:

java - 如何在 Android 中为 Spinner 设置所选项目

android - 如何实现 umano/AndroidSlidingUpPanel 库

android - 为什么BaseAdapter不需要括号?

java - 添加了读取手机状态权限但仍然崩溃

Android 离线可靠日期持续时间

java - 如何从 Android 中的 Activity 类中检索共享首选项到非 Activity 类中?

android - 可绘制图层列表中的动画项目

java - 如何在前一屏幕 android 中使用给定输入编号的 edittext 、 textview 和图像创建动态布局?

android - 从 Android TabHost 中的选项卡 Activity 更新选项卡

android - Android 中的 Intents 和 TabHost 问题