SettingsPreferenceService


public abstract class SettingsPreferenceService
extends Service

java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.app.Service
         ↳ android.service.settings.preferences.SettingsPreferenceService


Base class for a service that exposes its settings preferences to external access.

This class is to be implemented by apps that contribute to the Android Settings surface. Access to this service is permission guarded by ERROR(/android.permission.READ_SYSTEM_PREFERENCES) for binding and reading, and guarded by both ERROR(/android.permission.READ_SYSTEM_PREFERENCES) and ERROR(/android.permission.WRITE_SYSTEM_PREFERENCES) for writing. An additional checks for access control are the responsibility of the implementing class.

This implementation must correspond to an exported service declaration in the host app AndroidManifest.xml as follows

 <service
     android:permission="android.permission.READ_SYSTEM_PREFERENCES"
     android:exported="true">
     <intent-filter>
         <action android:name="android.service.settings.preferences.action.PREFERENCE_SERVICE" />
     </intent-filter>
 </service>
 

Summary

Constants

String ACTION_PREFERENCE_SERVICE

Intent Action corresponding to a SettingsPreferenceService.

Inherited constants

Public constructors

SettingsPreferenceService()

Public methods

final IBinder onBind(Intent intent)

Return the communication channel to the service.

abstract void onGetAllPreferenceMetadata(MetadataRequest request, OutcomeReceiver<MetadataResultException> callback)

Retrieve the metadata for all exposed settings preferences within this application.

abstract void onGetPreferenceValue(GetValueRequest request, OutcomeReceiver<GetValueResultException> callback)

Retrieve the current value of the requested settings preference.

abstract void onSetPreferenceValue(SetValueRequest request, OutcomeReceiver<SetValueResultException> callback)

Set the value within the request to the target settings preference.

Inherited methods

Constants

ACTION_PREFERENCE_SERVICE

Added in API level 36
public static final String ACTION_PREFERENCE_SERVICE

Intent Action corresponding to a SettingsPreferenceService. Note that any checks for such services must be accompanied by a check to ensure the host is a system application. Given an ApplicationInfo you can check for ApplicationInfo.FLAG_SYSTEM, or when querying PackageManager.queryIntentServices you can provide the flag PackageManager.MATCH_SYSTEM_ONLY.

Constant Value: "android.service.settings.preferences.action.PREFERENCE_SERVICE"

Public constructors

SettingsPreferenceService

public SettingsPreferenceService ()

Public methods

onBind

Added in API level 36
public final IBinder onBind (Intent intent)

Return the communication channel to the service. May return null if clients can not bind to the service. The returned IBinder is usually for a complex interface that has been described using aidl.

Note that unlike other application components, calls on to the IBinder interface returned here may not happen on the main thread of the process. More information about the main thread can be found in Processes and Threads.

Parameters
intent Intent: The Intent that was used to bind to this service, as given to Context.bindService. Note that any extras that were included with the Intent at that point will not be seen here.

Returns
IBinder Return an IBinder through which clients can call on to the service.

onGetAllPreferenceMetadata

Added in API level 36
public abstract void onGetAllPreferenceMetadata (MetadataRequest request, 
                OutcomeReceiver<MetadataResultException> callback)

Retrieve the metadata for all exposed settings preferences within this application. This data should be a snapshot of their state at the time of this method being called.

Parameters
request MetadataRequest: object to specify request parameters

callback OutcomeReceiver: object to receive result or failure of request

onGetPreferenceValue

Added in API level 36
public abstract void onGetPreferenceValue (GetValueRequest request, 
                OutcomeReceiver<GetValueResultException> callback)

Retrieve the current value of the requested settings preference. If this value is not exposed or cannot be obtained for some reason, the corresponding result code will be set on the result object.

Parameters
request GetValueRequest: object to specify request parameters

callback OutcomeReceiver: object to receive result or failure of request

onSetPreferenceValue

Added in API level 36
public abstract void onSetPreferenceValue (SetValueRequest request, 
                OutcomeReceiver<SetValueResultException> callback)

Set the value within the request to the target settings preference. If this value cannot be written for some reason, the corresponding result code will be set on the result object.

Parameters
request SetValueRequest: object to specify request parameters

callback OutcomeReceiver: object to receive result or failure of request