SettingsPreferenceServiceClient
public
class
SettingsPreferenceServiceClient
extends Object
implements
AutoCloseable
java.lang.Object | |
↳ | 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 PackageManager
for applications
that provide the intent action SettingsPreferenceService.ACTION_PREFERENCE_SERVICE
that
are also system applications (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, String packageName, Executor callbackExecutor, OutcomeReceiver<SettingsPreferenceServiceClient, Exception> clientReadyCallback)
Construct a client for binding to a |
Public methods | |
---|---|
void
|
close()
This client handles a resource, thus is it important to appropriately close that resource when it is no longer needed. |
void
|
getAllPreferenceMetadata(MetadataRequest request, Executor executor, OutcomeReceiver<MetadataResult, Exception> receiver)
Retrieve the metadata for all exposed settings preferences within the application. |
void
|
getPreferenceValue(GetValueRequest request, Executor executor, OutcomeReceiver<GetValueResult, Exception> receiver)
Retrieve the current value of the requested settings preference. |
void
|
setPreferenceValue(SetValueRequest request, Executor executor, OutcomeReceiver<SetValueResult, Exception> receiver)
Set the value on the target settings preference. |
Inherited methods | |
---|---|
Public constructors
SettingsPreferenceServiceClient
public SettingsPreferenceServiceClient (Context context, String packageName, Executor callbackExecutor, OutcomeReceiver<SettingsPreferenceServiceClient, Exception> clientReadyCallback)
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 : callback invoked once the client is ready, error otherwise |
Public methods
close
public void close ()
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.
getAllPreferenceMetadata
public void getAllPreferenceMetadata (MetadataRequest request, Executor executor, OutcomeReceiver<MetadataResult, Exception> receiver)
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 : callback to receive the result or failure |
getPreferenceValue
public void getPreferenceValue (GetValueRequest request, Executor executor, OutcomeReceiver<GetValueResult, Exception> receiver)
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 : callback to receive the result or failure |
setPreferenceValue
public void setPreferenceValue (SetValueRequest request, Executor executor, OutcomeReceiver<SetValueResult, Exception> receiver)
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 : callback to receive the result or failure |