Невозможно прочитать общие настройки моего другого приложения

Просто используйте TheClassName.class вместо getClass().

0
задан AnswerDroid 6 March 2019 в 10:33
поделиться

2 ответа

первое приложение:

SharedPreferences prefs = getSharedPreferences("test_prefs",
                Context.MODE_WORLD_READABLE);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putBoolean("pref_key", true);
        editor.commit();

второе приложение:

/* where com.example is the first app containing the preferences */
Context myContext = createPackageContext("com.example",Context.CONTEXT_IGNORE_SECURITY); 

SharedPreferences testPrefs = myContext.getSharedPreferences 
    ("test_prefs", Context.MODE_WORLD_READABLE); 


 boolean data = pref.getBoolean("pref_key", false);
0
ответ дан Neeraj Singh 6 March 2019 в 10:33
поделиться

Правильный способ сделать это - создать службу в App1 и привязать к ней службу из App2.

Вот ссылка для справки. https://stuff.mit.edu/afs/sipb/project/android/docs/guide/components/bound-services.html

0
ответ дан hashcode 6 March 2019 в 10:33
поделиться
Другие вопросы по тегам:

Похожие вопросы: