Methods that offers Context open sharedPreferences only from the application package folder, and what if I need to open such a file from external storage? How to access it to read it as sharedPreferences

    1 answer 1

    You can use SharedPreferences with the Context.MODE_WORLD_READABLE flag.

    In the first application, write the values:

     SharedPreferences sharedPreferences = getSharedPreferences("some_prefs", Context.MODE_WORLD_READABLE); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("SOME_VALUE_KEY", "some_value"); editor.commit(); 

    In the second we read them:

     Context context = createPackageContext("%FIRST_APP_PACKAGE%", 0); SharedPreferences sharedPreferences = context.getSharedPreferences("some_prefs", Context.MODE_PRIVATE); String value = sharedPreferences.getString("SOME_VALUE_KEY", "Empty value"); 

    However , the Context.MODE_WORLD_READABLE and Context.MODE_WORLD_WRITEABLE in API level 17 are marked deprecated indicating that this is bad from a security point of view.