Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.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 Android获取另一个应用程序的共享首选项_Java_Android_Sharedpreferences_Preferences_Shared - Fatal编程技术网

Java Android获取另一个应用程序的共享首选项

Java Android获取另一个应用程序的共享首选项,java,android,sharedpreferences,preferences,shared,Java,Android,Sharedpreferences,Preferences,Shared,我试图从另一个应用程序的Word可读共享首选项中获取一些数据 我确信其他应用程序共享首选项是世界可读的,并且名称是存在的 但我正在检索空字符串 这是我的密码: package com.example.sharedpref; import androidx.appcompat.app.AppCompatActivity; import android.content.Context; import android.content.pm.PackageManager; import android.

我试图从另一个应用程序的Word可读共享首选项中获取一些数据

我确信其他应用程序共享首选项是世界可读的,并且名称是存在的

但我正在检索空字符串

这是我的密码:

package com.example.sharedpref;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.widget.TextView;
import android.content.SharedPreferences;

public class MainActivity extends AppCompatActivity {
    private TextView appContent;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        appContent = (TextView) findViewById(R.id.test1);
        appContent.setText("Test Application\n");
        appContent.setText(getName(this));
    }
    protected String getName(Context context){
        Context packageContext = null;
        try {
            packageContext = context.createPackageContext("com.application", CONTEXT_IGNORE_SECURITY);
            SharedPreferences sharedPreferences = packageContext.getSharedPreferences("name_conf", 0);
            String name = sharedPreferences.getString("name", "");
        return  name; //HERE IS WHERE I PUT BREAKPOINT
        }

        catch (PackageManager.NameNotFoundException e) {
            return null;

        }
    }
}
以下是我从调试模式中检索到的一些调试:

以及我尝试访问共享首选项的应用程序中的一段代码:

    /* access modifiers changed from: protected */
    @SuppressLint({"WorldReadableFiles"})
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_welcome);
        Editor edit = getApplicationContext().getSharedPreferences("name_conf", 0).edit();
        edit.putBoolean("FIRSTRUN", false);
        edit.putString("name", "Eddie");
        edit.commit();
        new DBHelper(this).getReadableDatabase();
另外,我无法编辑我尝试访问的第二个应用程序的代码!
我缺少什么?

您可以不从其他应用程序编辑它,
如果需要,您可以使用FileWriter创建一个txt文件,并在其他应用程序中使用它

结果与debbuger中的上述结果相同。