Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从不同的应用程序访问SharedReference文件_Java_Android_Preferences - Fatal编程技术网

Java 从不同的应用程序访问SharedReference文件

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

我正在尝试访问一个共享首选项文件,该文件是在另一个应用程序中创建的。我学习了一些教程,但没有学习。这就是我的情况:

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))


这应该可以解决问题。在调用之前,也不要调用当前上下文的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);