gpt4 book ai didi

android - 无法访问在 Android 的帐户验证器中设置的首选项

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:08:52 26 4
gpt4 key购买 nike

我通过帐户验证器在复选框中设置首选项:

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);

有人知道可以从哪里访问基于帐户验证器的首选项吗?

最佳答案

在基于auth_preferences.xml 的Activity 中所做的更改被保存到com.android.settings_preferences.xml 并且无法使用您的应用程序的 访问它>getSharedPreferences(文件,上下文)。我发现的常见解决方案是改为在帐户偏好设置中触发新的 PreferenceActivity

关于android - 无法访问在 Android 的帐户验证器中设置的首选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5885445/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com