Не удается получить доступ к настройкам, установленным в аккаунте-аутентификаторе в Android - PullRequest
4 голосов
/ 04 мая 2011

Я установил предпочтение в чекбоксе через учетную запись-аутентификатор:

Intent settingsIntent = new Intent("android.settings.ACCOUNT_SYNC_SETTINGS");
settingsIntent.putExtra("account", mActiveAccount);
startActivityForResult(settingsIntent, ACCOUNT_COMPLETE);

с xml:

<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="com.example.auth"
android:label="@string/auth_label"
android:accountPreferences="@xml/auth_preferences" />

и в auth_preferences.xml у меня есть:

<?xml version="1.0" encoding="UTF-8" ?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/auth_preferences_general_group" />
<PreferenceScreen android:key="account_settings"
    android:title="@string/auth_preferences_general_details_title" 
    android:summary="@string/auth_preferences_general_details_description">
    <intent android:action="com.example.ACCOUNT_SETUP"
        android:targetPackage="com.example.core"
        android:targetClass="com.example.authentication.AuthenticatorAccountOptions" />
</PreferenceScreen>
<PreferenceCategory android:title="@string/auth_preferences_data_sync_group" >
    <CheckBoxPreference
          android:key="checkbox_pref"
          android:title="@string/auth_preferences_data_sync_syncwidget_title" 
          android:summary="@string/auth_preferences_data_sync_syncwidget_description"
          android:defaultValue="true"
          android:persistent="true" />  
</PreferenceCategory>   

Но я не могу получить доступ к настройкам этого флажка в основном коде, когда пытаюсь его получить:

SharedPreferences prefs = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE);
boolean isChecked = prefs.getBoolean("checkbox_pref", true);

Кто-нибудь знает, где находится учетная запись-Доступ к настройкам на основе аутентификатора можно получить из?

1 Ответ

3 голосов
/ 02 января 2012

Изменения, внесенные в Activity на основе auth_preferences.xml, сохраняются в com.android.settings_preferences.xml, и к ним нельзя получить доступ с помощью getSharedPreferences(file, context) вашего приложения.Распространенное решение, которое я нашел, состоит в том, чтобы вместо этого вызывать новый PreferenceActivity в настройках аккаунта.

...