无法访问Android中设置的帐户身份验证preferences [英] Can't access preferences set in account-authenticator in Android
问题描述
我的设置通过一个账户认证器preference的复选框:
I'm settings a preference in a checkbox via an account-authenticator:
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我有:
and in auth_preferences.xml I have:
<?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>
但我不能当我尝试访问的主要code此复选框preferences并检索它:
But I'm unable to access this checkbox preferences in the main code when I try and retrieve it :
SharedPreferences prefs = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE);
boolean isChecked = prefs.getBoolean("checkbox_pref", true);
任何人都知道的帐户身份验证基于preferences可以访问?
Anyone know where the account-authenticator based preferences can be accessed from?
推荐答案
在根据 auth_ preferences.xml
的活动所做的更改将保存到 com.android.settings_ preferences.xml
,它不能使用你的应用程序的 getShared preferences(文件,环境)访问
。我找到共同的解决办法是引发新 preferenceActivity
帐户preferences代替。
The changes made in the Activity based on auth_preferences.xml
are saved to com.android.settings_preferences.xml
and it can't be accessed using your application's getSharedPreferences(file, context)
. Common solution I found is to trigger a new PreferenceActivity
in account preferences instead.
这篇关于无法访问Android中设置的帐户身份验证preferences的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!