SettingsPreferenceServiceClient
open class SettingsPreferenceServiceClient : AutoCloseable
kotlin.Any | |
↳ | android.service.settings.preferences.SettingsPreferenceServiceClient |
Client class responsible for binding to and interacting with an instance of SettingsPreferenceService
.
This is a convenience class to handle the lifecycle of the service connection.
This client will only interact with one instance at a time, so if the caller requires multiple instances (multiple applications that provide settings), then the caller must create multiple client classes, one for each instance required. To find all available services, a caller may query android.content.pm.PackageManager
for applications that provide the intent action SettingsPreferenceService.ACTION_PREFERENCE_SERVICE
that are also system applications (android.content.pm.ApplicationInfo#FLAG_SYSTEM
).
Note: Each instance of this client will open a binding to an application. This can be resource intensive and affect the health of the system. It is essential that each client instance is only used when needed and the number of calls made are minimal.
Summary
Public constructors | |
---|---|
SettingsPreferenceServiceClient(context: Context, packageName: String, callbackExecutor: Executor, clientReadyCallback: OutcomeReceiver<SettingsPreferenceServiceClient!, Exception!>) Construct a client for binding to a |
Public methods | |
---|---|
open Unit |
close() This client handles a resource, thus is it important to appropriately close that resource when it is no longer needed. |
open Unit |
getAllPreferenceMetadata(request: MetadataRequest, executor: Executor, receiver: OutcomeReceiver<MetadataResult!, Exception!>) Retrieve the metadata for all exposed settings preferences within the application. |
open Unit |
getPreferenceValue(request: GetValueRequest, executor: Executor, receiver: OutcomeReceiver<GetValueResult!, Exception!>) Retrieve the current value of the requested settings preference. |
open Unit |
setPreferenceValue(request: SetValueRequest, executor: Executor, receiver: OutcomeReceiver<SetValueResult!, Exception!>) Set the value on the target settings preference. |
Public constructors
SettingsPreferenceServiceClient
SettingsPreferenceServiceClient(
context: Context,
packageName: String,
callbackExecutor: Executor,
clientReadyCallback: OutcomeReceiver<SettingsPreferenceServiceClient!, Exception!>)
Construct a client for binding to a SettingsPreferenceService
provided by the application corresponding to the provided package name.
Parameters | |
---|---|
context |
Context: Application context |
packageName |
String: package name for which this client will initiate a service binding |
callbackExecutor |
Executor: executor on which to invoke clientReadyCallback Callback and listener events are dispatched through this Executor , providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor() . Otherwise, provide an Executor that dispatches to an appropriate thread. |
clientReadyCallback |
OutcomeReceiver<SettingsPreferenceServiceClient!, Exception!>: callback invoked once the client is ready, error otherwise |
Public methods
close
open fun close(): Unit
This client handles a resource, thus is it important to appropriately close that resource when it is no longer needed.
This method is provided by AutoCloseable
and calling it will unbind any service binding.
Exceptions | |
---|---|
java.lang.Exception |
if this resource cannot be closed |
getAllPreferenceMetadata
open fun getAllPreferenceMetadata(
request: MetadataRequest,
executor: Executor,
receiver: OutcomeReceiver<MetadataResult!, Exception!>
): Unit
Retrieve the metadata for all exposed settings preferences within the application.
Parameters | |
---|---|
request |
MetadataRequest: object to specify request parameters |
executor |
Executor: Executor on which to invoke the receiver Callback and listener events are dispatched through this Executor , providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor() . Otherwise, provide an Executor that dispatches to an appropriate thread. |
receiver |
OutcomeReceiver<MetadataResult!, Exception!>: callback to receive the result or failure |
getPreferenceValue
open fun getPreferenceValue(
request: GetValueRequest,
executor: Executor,
receiver: OutcomeReceiver<GetValueResult!, Exception!>
): Unit
Retrieve the current value of the requested settings preference.
Parameters | |
---|---|
request |
GetValueRequest: object to specify request parameters |
executor |
Executor: Executor on which to invoke the receiver Callback and listener events are dispatched through this Executor , providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor() . Otherwise, provide an Executor that dispatches to an appropriate thread. |
receiver |
OutcomeReceiver<GetValueResult!, Exception!>: callback to receive the result or failure |
setPreferenceValue
open fun setPreferenceValue(
request: SetValueRequest,
executor: Executor,
receiver: OutcomeReceiver<SetValueResult!, Exception!>
): Unit
Set the value on the target settings preference.
Parameters | |
---|---|
request |
SetValueRequest: object to specify request parameters |
executor |
Executor: Executor on which to invoke the receiver Callback and listener events are dispatched through this Executor , providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor() . Otherwise, provide an Executor that dispatches to an appropriate thread. |
receiver |
OutcomeReceiver<SetValueResult!, Exception!>: callback to receive the result or failure |