# SettingsPreferenceServiceClient

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Ctors](https://developer.android.com/reference/android/service/settings/preferences/SettingsPreferenceServiceClient#pubctors)\|[Methods](https://developer.android.com/reference/android/service/settings/preferences/SettingsPreferenceServiceClient#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/service/settings/preferences/SettingsPreferenceServiceClient#inhmethods)  

# SettingsPreferenceServiceClient

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/service/settings/preferences/SettingsPreferenceServiceClient "View this page in Kotlin")\|Java

`
public


class
SettingsPreferenceServiceClient
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


implements

`[AutoCloseable](https://developer.android.com/reference/java/lang/AutoCloseable)`


`

|---|----------------------------------------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.service.settings.preferences.SettingsPreferenceServiceClient |

<br />

*** ** * ** ***

Client class responsible for binding to and interacting with an instance of[SettingsPreferenceService](https://developer.android.com/reference/android/service/settings/preferences/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](https://developer.android.com/reference/android/content/pm/PackageManager)for applications that provide the intent action[SettingsPreferenceService.ACTION_PREFERENCE_SERVICE](https://developer.android.com/reference/android/service/settings/preferences/SettingsPreferenceService#ACTION_PREFERENCE_SERVICE)that are also system applications ([ApplicationInfo.FLAG_SYSTEM](https://developer.android.com/reference/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](https://developer.android.com/reference/android/service/settings/preferences/SettingsPreferenceServiceClient#SettingsPreferenceServiceClient(android.content.Context,%20java.lang.String,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<android.service.settings.preferences.SettingsPreferenceServiceClient,java.lang.Exception>))`(`[Context](https://developer.android.com/reference/android/content/Context)` context, `[String](https://developer.android.com/reference/java/lang/String)` packageName, `[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)` callbackExecutor, `[OutcomeReceiver](https://developer.android.com/reference/android/os/OutcomeReceiver)`<`[SettingsPreferenceServiceClient](https://developer.android.com/reference/android/service/settings/preferences/SettingsPreferenceServiceClient)`, `[Exception](https://developer.android.com/reference/java/lang/Exception)`> clientReadyCallback) ` Construct a client for binding to a[SettingsPreferenceService](https://developer.android.com/reference/android/service/settings/preferences/SettingsPreferenceService)provided by the application corresponding to the provided package name. |

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ### Public methods                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     ||
|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void` | ` `[close](https://developer.android.com/reference/android/service/settings/preferences/SettingsPreferenceServiceClient#close())`() ` This client handles a resource, thus is it important to appropriately close that resource when it is no longer needed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ` void` | ` `[getAllPreferenceMetadata](https://developer.android.com/reference/android/service/settings/preferences/SettingsPreferenceServiceClient#getAllPreferenceMetadata(android.service.settings.preferences.MetadataRequest,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<android.service.settings.preferences.MetadataResult,java.lang.Exception>))`(`[MetadataRequest](https://developer.android.com/reference/android/service/settings/preferences/MetadataRequest)` request, `[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)` executor, `[OutcomeReceiver](https://developer.android.com/reference/android/os/OutcomeReceiver)`<`[MetadataResult](https://developer.android.com/reference/android/service/settings/preferences/MetadataResult)`, `[Exception](https://developer.android.com/reference/java/lang/Exception)`> receiver) ` Retrieve the metadata for all exposed settings preferences within the application. |
| ` void` | ` `[getPreferenceValue](https://developer.android.com/reference/android/service/settings/preferences/SettingsPreferenceServiceClient#getPreferenceValue(android.service.settings.preferences.GetValueRequest,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<android.service.settings.preferences.GetValueResult,java.lang.Exception>))`(`[GetValueRequest](https://developer.android.com/reference/android/service/settings/preferences/GetValueRequest)` request, `[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)` executor, `[OutcomeReceiver](https://developer.android.com/reference/android/os/OutcomeReceiver)`<`[GetValueResult](https://developer.android.com/reference/android/service/settings/preferences/GetValueResult)`, `[Exception](https://developer.android.com/reference/java/lang/Exception)`> receiver) ` Retrieve the current value of the requested settings preference.                               |
| ` void` | ` `[setPreferenceValue](https://developer.android.com/reference/android/service/settings/preferences/SettingsPreferenceServiceClient#setPreferenceValue(android.service.settings.preferences.SetValueRequest,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<android.service.settings.preferences.SetValueResult,java.lang.Exception>))`(`[SetValueRequest](https://developer.android.com/reference/android/service/settings/preferences/SetValueRequest)` request, `[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)` executor, `[OutcomeReceiver](https://developer.android.com/reference/android/os/OutcomeReceiver)`<`[SetValueResult](https://developer.android.com/reference/android/service/settings/preferences/SetValueResult)`, `[Exception](https://developer.android.com/reference/java/lang/Exception)`> receiver) ` Set the value on the target settings preference.                                               |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||
| From interface` `[java.lang.AutoCloseable](https://developer.android.com/reference/java/lang/AutoCloseable)` ` |------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[close](https://developer.android.com/reference/java/lang/AutoCloseable#close())`() ` Closes this resource, relinquishing any underlying resources. | ||

## Public constructors

### SettingsPreferenceServiceClient

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public SettingsPreferenceServiceClient (Context context, 
                String packageName, 
                Executor callbackExecutor, 
                OutcomeReceiver<SettingsPreferenceServiceClient, Exception> clientReadyCallback)
```

Construct a client for binding to a[SettingsPreferenceService](https://developer.android.com/reference/android/service/settings/preferences/SettingsPreferenceService)provided by the application corresponding to the provided package name.

<br />

|                                                                                                                                                                                                                                                                                                               Parameters                                                                                                                                                                                                                                                                                                               ||
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context`             | `Context`: Application context <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `packageName`         | `String`: package name for which this client will initiate a service binding <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `callbackExecutor`    | `Executor`: executor on which to invoke clientReadyCallback Callback and listener events are dispatched through this[Executor](https://developer.android.com/reference/java/util/concurrent/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()](https://developer.android.com/reference/android/content/Context#getMainExecutor()). Otherwise, provide an[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)that dispatches to an appropriate thread. <br /> |
| `clientReadyCallback` | `OutcomeReceiver`: callback invoked once the client is ready, error otherwise <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |

## Public methods

### close

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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](https://developer.android.com/reference/java/lang/AutoCloseable)and calling it will unbind any service binding.

<br />

### getAllPreferenceMetadata

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void getAllPreferenceMetadata (MetadataRequest request, 
                Executor executor, 
                OutcomeReceiver<MetadataResult, Exception> receiver)
```

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

<br />

|                                                                                                                                                                                                                                                                                                                                         Parameters                                                                                                                                                                                                                                                                                                                                          ||
|------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `request`  | `MetadataRequest`: object to specify request parameters <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `executor` | `Executor`:[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)on which to invoke the receiver Callback and listener events are dispatched through this[Executor](https://developer.android.com/reference/java/util/concurrent/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()](https://developer.android.com/reference/android/content/Context#getMainExecutor()). Otherwise, provide an[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)that dispatches to an appropriate thread. <br /> |
| `receiver` | `OutcomeReceiver`: callback to receive the result or failure <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |

### getPreferenceValue

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void getPreferenceValue (GetValueRequest request, 
                Executor executor, 
                OutcomeReceiver<GetValueResult, Exception> receiver)
```

Retrieve the current value of the requested settings preference.

<br />

|                                                                                                                                                                                                                                                                                                                                         Parameters                                                                                                                                                                                                                                                                                                                                          ||
|------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `request`  | `GetValueRequest`: object to specify request parameters <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `executor` | `Executor`:[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)on which to invoke the receiver Callback and listener events are dispatched through this[Executor](https://developer.android.com/reference/java/util/concurrent/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()](https://developer.android.com/reference/android/content/Context#getMainExecutor()). Otherwise, provide an[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)that dispatches to an appropriate thread. <br /> |
| `receiver` | `OutcomeReceiver`: callback to receive the result or failure <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |

### setPreferenceValue

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setPreferenceValue (SetValueRequest request, 
                Executor executor, 
                OutcomeReceiver<SetValueResult, Exception> receiver)
```

Set the value on the target settings preference.

<br />

|                                                                                                                                                                                                                                                                                                                                         Parameters                                                                                                                                                                                                                                                                                                                                          ||
|------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `request`  | `SetValueRequest`: object to specify request parameters <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `executor` | `Executor`:[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)on which to invoke the receiver Callback and listener events are dispatched through this[Executor](https://developer.android.com/reference/java/util/concurrent/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()](https://developer.android.com/reference/android/content/Context#getMainExecutor()). Otherwise, provide an[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)that dispatches to an appropriate thread. <br /> |
| `receiver` | `OutcomeReceiver`: callback to receive the result or failure <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |