Android PreferenceActivity for creating MODE_WORLD_WRITEABLE preferences in applications

I have several applications that exchange certain data using settings. Each application sets its preferences through PreferenceActitivity (from xml). Two questions:

How to use / edit settings created by one application in another application. If I figure out how to create the MODE_WORLD_WRITEABLE settings using the PreferenceActivity function, which will solve the problem.

 SharedPreferences prefs = getSharedPreferences(
          <String referring to another package´s prefs>, MODE_WORLD_WRITEABLE);
        HashMap<String, String> map = (HashMap<String, String>) prefs
          .getAll();


        String str = map.toString();
        tv.setText(str);

Above code returns {}

  • Secondly, how do I use addPreferencesFromIntent (i) - I get a NullPointerException, although the intent is not Null.

Thanks for the help in advance.

Best, Samir

+3
1

, android: sharedUserId. MODE_PRIVATE ( ).

, , :

try {
            Context c = createPackageContext(com.app.first, MODE_PRIVATE);
            SharedPreferences prefs = c.getSharedPreferences(
                    "com.app.first_preferences", MODE_PRIVATE);

        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }

@CommonsWare Karthik Shanmugam !

+6

Source: https://habr.com/ru/post/1760872/


All Articles