Android: read the settings set in xml authenticator

I want to read in my code settings that I installed through the authenticator XML file. I found it is impossible to access the settings set in the authenticator account in Android and How to access the settings set in the authenticator account in Android one completely does not respond and the other says that I need to create my own activity. It really sounds weird as it means that the settings that I can configure through xml are useless because I can never read them. It cannot be. Does anyone know more about this? If I really need to create my own action, how would I do this in the case of an authenticator?

+7
android
source share
1 answer

From the documentation for AbstractAccountAuthenticator :

The preference attribute points to the xml hierarchy of the PreferenceScreen, which contains a list of PreferenceScreens that can be called to manage the authenticator. Example:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceCategory android:title="@string/title_fmt"/> <PreferenceScreen android:key="key1" android:title="@string/key1_action" android:summary="@string/key1_summary"> <intent android:action="key1.ACTION" android:targetPackage="key1.package" android:targetClass="key1.class"/> </PreferenceScreen> </PreferenceScreen> 

Thus, it seems that even if you can set individual preferences in account_preferences.xml , it is not assumed that the values ​​are not available.

See this question and answer for how to set up and process a PreferenceScreen intent.

EDIT

For a very simple working example, you can download the sample application from the "Sync Adapter Training Documents" and modify it as follows.

Create res/xml/account_preferences.xml that looks like

 <?xml version="1.0" encoding="UTF-8" ?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceCategory android:title="Category"/> <PreferenceScreen android:key="key1" android:title="@string/app_name" android:summary="@string/account_name"> <intent android:targetPackage="com.example.android.network.sync.basicsyncadapter" android:targetClass="com.example.android.network.sync.basicsyncadapter.EntryListActivity"/> </PreferenceScreen> </PreferenceScreen> 

Add android:accountPreferences="@xml/account_preferences" to the account-authenticator tag in authenticator.xml .

This example starts the action in this example, but you can easily launch the PreferenceActivity (or any other action you want). For more information on setting PreferenceActivity, see Settings .

For a real world example from the main Android application, see the implementation of the email application here .

0
source share

All Articles