假设我有这样的文件XML:
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
<string name="ActivationCode">c4ec5e61f49897192ad0744b27ad985f31d84a3458aeec628b5df809a246c1418ce4b52e9d07d15ab2377fd1e946fe1ad880ee8ca6359d0bda7e6502c10494d4ec612624f28b43727f2b6e5ec18959c53ebc90f97c636c5fe787f513c0a851686b2ccf1e8592df21e2a8d9370103750220ec47ff8267d036841592dc3e110334de8f136e2af9c1f100ba9a64fc7974ea</string>
</map>
我想在非根系的Android系统中将此文件插入此目录:
\数据\数据\ com.mycompany.my \ shared_prefs \
我该如何解决这个问题......所有答案都会受到赞赏......谢谢
答案 0 :(得分:1)
存储到共享偏好:
//Creating or modifying preference
SharedPreferences.Editor editor = getSharedPreferences("Activation", MODE_PRIVATE).edit();
//editor.putString("KEY","Value");
editor.putString("ActivationCode", "c4ec5e61f49897192ad0744b27ad985f31d84a3458aeec628b5df809a246c1418ce4b52e9d07d15ab2377fd1e946fe1ad880ee8ca6359d0bda7e6502c10494d4ec612624f28b43727f2b6e5ec18959c53ebc90f97c636c5fe787f513c0a851686b2ccf1e8592df21e2a8d9370103750220ec47ff8267d036841592dc3e110334de8f136e2af9c1f100ba9a64fc7974ea");
editor.commit();
从共享偏好中检索:
SharedPreferences sh = getSharedPreferences("Activation", MODE_PRIVATE).edit();
//sh.getString("KEY","Default value");
String activation = sh.getString("ActivationCode",null);
了解更多内容请参考: http://developer.android.com/training/basics/data-storage/shared-preferences.html