Java 从不同的应用程序访问SharedReference文件
我正在尝试访问一个共享首选项文件,该文件是在另一个应用程序中创建的。我学习了一些教程,但没有学习。这就是我的情况: App1(com.example.remoteservice) App2(com.example.grafica) 并返回0,因为不存在“telo”。为什么 谢谢App1(com.example.remoteservice) 共享参考配置2; configuracion2=getSharedReferences(“telo”,Context.MODE\u WORLD\u READABLE) App2(com.example.grafica) Log.i(“smash”、“ancho”+字符串.valueOf(ancho))Java 从不同的应用程序访问SharedReference文件,java,android,preferences,Java,Android,Preferences,我正在尝试访问一个共享首选项文件,该文件是在另一个应用程序中创建的。我学习了一些教程,但没有学习。这就是我的情况: App1(com.example.remoteservice) App2(com.example.grafica) 并返回0,因为不存在“telo”。为什么 谢谢App1(com.example.remoteservice) 共享参考配置2; configuracion2=getSharedReferences(“telo”,Context.MODE\u WORLD\u READA
这应该可以解决问题。在调用之前,也不要调用当前上下文的getSharedReferences()。看看它是否与我的代码相同
SharedPreferences configuracion2;
configuracion2 = getSharedPreferences("telo", Context.MODE_WORLD_READABLE);
Editor editor = configuracion2.edit();
editor.putFloat("x21", Float.parseFloat(x21.getText().toString()));
editor.commit();
Context con = createPackageContext("com.example.remoteservice", MODE_WORLD_WRITEABLE);
SharedPreferences pref = con.getSharedPreferences(
"telo",MODE_WORLD_READABLE);
ancho = pref.getFloat("x21", 0);
Log.i("smash", "ancho" + String.valueOf(ancho));
Editor editor = configuracion2.edit();
editor.putFloat("x21", Float.parseFloat(x21.getText().toString()));
editor.commit();
Context con = createPackageContext("com.example.remoteservice", Context.CONTEXT_IGNORE_SECURITY);
SharedPreferences pref = con.getSharedPreferences(
"telo",MODE_WORLD_READABLE);
ancho = pref.getFloat("x21", 0);