在我的应用上,我正在尝试从另一个测试应用的共享pref文件中读取值。它包含一个字符串值。我试图在我的应用程序上使用以下代码,但没有为Item1显示值:
file file = new File(“/ data / data / com.appmanager / shared_prefs / appmanager_conf.xml”);
try {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.parse(file);
pin = document.getElementsByTagName("ITEM1").item(0).getTextContent();
} catch (Exception ex) {
ex.printStackTrace();
}
我首先在下面做了这个:
String key =“”; try {con = createPackageContext(“com.application1”,Context.CONTEXT_IGNORE_SECURITY); SharedPreferences prefs = con.getSharedPreferences(“passmanager_conf”,MODE_PRIVATE); key = prefs.getString(“ITEM1”,“找不到”); Log.i(“mainActivity”,“我的项目是”+键); } catch(PackageManager.NameNotFoundException e){Log.e(“Not Data Shared”,e.toString()); }