| 
    Tizen Native API
    5.5
    
   
   | 
  
  
  
 
The Preference API provides functions to store and retrieve small pieces of data used for application preferences.
#include <app_preference.h>
The Preference API provides a mechanism that saves data items in the form of key/value pairs for this application, and later retrieves them. A typical usecase would be for an application preference screen where the user can pick some values for some options. The Preference API has pairs of functions, one to set such a pair, another to retrieve the stored value given in the key. Keys are always text strings, but there are functions for each of the possible value types: integer, double, string, and boolean. There is also a function to clear all of the preferences. The Preference API provides a way to register a callback to get notified when a value for a particular key changes. It is useful to know when the display should be updated or some behavior is altered as a result. There is an iterator function which steps through all the data pairs, invoking a callback for each one.
Functions | |
| int | preference_set_int (const char *key, int value) | 
| Sets an integer value in the preference.   | |
| int | preference_get_int (const char *key, int *value) | 
| Gets an integer value from the preference.   | |
| int | preference_set_double (const char *key, double value) | 
| Sets a double value in the preference.   | |
| int | preference_get_double (const char *key, double *value) | 
| Gets a double value from the preference.   | |
| int | preference_set_string (const char *key, const char *value) | 
| Sets a string value in the preference.   | |
| int | preference_get_string (const char *key, char **value) | 
| Gets a string value from the preference.   | |
| int | preference_set_boolean (const char *key, bool value) | 
| Sets a boolean value in the preference.   | |
| int | preference_get_boolean (const char *key, bool *value) | 
| Gets a boolean value from the preference.   | |
| int | preference_remove (const char *key) | 
| Removes any value with the given key from the preference.   | |
| int | preference_is_existing (const char *key, bool *existing) | 
| Checks whether the given key exists in the preference.   | |
| int | preference_remove_all (void) | 
| Removes all key-value pairs from the preference.   | |
| int | preference_set_changed_cb (const char *key, preference_changed_cb callback, void *user_data) | 
| Registers a callback function to be invoked when value of the given key in the preference changes.   | |
| int | preference_unset_changed_cb (const char *key) | 
| Unregisters the callback function.   | |
| int | preference_foreach_item (preference_item_cb callback, void *user_data) | 
| Retrieves all key-value pairs in the preference by invoking the callback function.   | |
Typedefs | |
| typedef void(* | preference_changed_cb )(const char *key, void *user_data) | 
| Called when the given key's value in the preference changes.   | |
| typedef bool(* | preference_item_cb )(const char *key, void *user_data) | 
| Called to get key string, once for each key-value pair in the preference.   | |
| typedef void(* preference_changed_cb)(const char *key, void *user_data) | 
Called when the given key's value in the preference changes.
When the key is added or removed, this callback function is skipped(only update can be handled).
| [in] | key | The name of the key in the preference | 
| [in] | user_data | The user data passed from the callback registration function | 
| typedef bool(* preference_item_cb)(const char *key, void *user_data) | 
Called to get key string, once for each key-value pair in the preference.
| [in] | key | The key of the value added to the preference | 
| [in] | user_data | The user data passed from the foreach function | 
true to continue with the next iteration of the loop, otherwise false to break out of the loop | enum preference_error_e | 
| int preference_foreach_item | ( | preference_item_cb | callback, | 
| void * | user_data | ||
| ) | 
Retrieves all key-value pairs in the preference by invoking the callback function.
| [in] | callback | The callback function to get key value once for each key-value pair in the preference | 
| [in] | user_data | The user data to be passed to the callback function | 
0 on success, otherwise a negative error value | PREFERENCE_ERROR_NONE | Successful | 
| PREFERENCE_ERROR_INVALID_PARAMETER | Invalid parameter | 
| PREFERENCE_ERROR_IO_ERROR | Internal I/O Error | 
| int preference_get_boolean | ( | const char * | key, | 
| bool * | value | ||
| ) | 
Gets a boolean value from the preference.
| [in] | key | The name of the key to retrieve | 
| [out] | value | The boolean value associated with the given key  | 
0 on success, otherwise a negative error value | PREFERENCE_ERROR_NONE | Successful | 
| PREFERENCE_ERROR_INVALID_PARAMETER | Invalid parameter | 
| PREFERENCE_ERROR_OUT_OF_MEMORY | Out of memory | 
| PREFERENCE_ERROR_NO_KEY | Required key not available | 
| PREFERENCE_ERROR_IO_ERROR | Internal I/O Error | 
| int preference_get_double | ( | const char * | key, | 
| double * | value | ||
| ) | 
Gets a double value from the preference.
| [in] | key | The name of the key to retrieve | 
| [out] | value | The double value associated with the given key  | 
0 on success, otherwise a negative error value | PREFERENCE_ERROR_NONE | Successful | 
| PREFERENCE_ERROR_INVALID_PARAMETER | Invalid parameter | 
| PREFERENCE_ERROR_OUT_OF_MEMORY | Out of memory | 
| PREFERENCE_ERROR_NO_KEY | Required key not available | 
| PREFERENCE_ERROR_IO_ERROR | Internal I/O Error | 
| int preference_get_int | ( | const char * | key, | 
| int * | value | ||
| ) | 
Gets an integer value from the preference.
| [in] | key | The name of the key to retrieve | 
| [out] | value | The int value for the given key  | 
0 on success, otherwise a negative error value | PREFERENCE_ERROR_NONE | Successful | 
| PREFERENCE_ERROR_INVALID_PARAMETER | Invalid parameter | 
| PREFERENCE_ERROR_OUT_OF_MEMORY | Out of memory | 
| PREFERENCE_ERROR_NO_KEY | Required key not available | 
| PREFERENCE_ERROR_IO_ERROR | Internal I/O Error | 
| int preference_get_string | ( | const char * | key, | 
| char ** | value | ||
| ) | 
Gets a string value from the preference.
| [in] | key | The name of the key to retrieve | 
| [out] | value | The string value associated with the given key  | 
0 on success, otherwise a negative error value | PREFERENCE_ERROR_NONE | Successful | 
| PREFERENCE_ERROR_INVALID_PARAMETER | Invalid parameter | 
| PREFERENCE_ERROR_OUT_OF_MEMORY | Out of memory | 
| PREFERENCE_ERROR_NO_KEY | Required key not available | 
| PREFERENCE_ERROR_IO_ERROR | Internal I/O Error | 
| int preference_is_existing | ( | const char * | key, | 
| bool * | existing | ||
| ) | 
Checks whether the given key exists in the preference.
| [in] | key | The name of the key to check | 
| [out] | existing | If true the key exists in the preference, otherwise false  | 
0 on success, otherwise a negative error value | PREFERENCE_ERROR_NONE | Successful | 
| PREFERENCE_ERROR_INVALID_PARAMETER | Invalid parameter | 
| PREFERENCE_ERROR_OUT_OF_MEMORY | Out of memory | 
| PREFERENCE_ERROR_IO_ERROR | Internal I/O Error | 
| int preference_remove | ( | const char * | key | ) | 
Removes any value with the given key from the preference.
| [in] | key | The name of the key to remove | 
0 on success, otherwise a negative error value | PREFERENCE_ERROR_NONE | Successful | 
| PREFERENCE_ERROR_INVALID_PARAMETER | Invalid parameter | 
| PREFERENCE_ERROR_OUT_OF_MEMORY | Out of memory | 
| PREFERENCE_ERROR_NO_KEY | Required key not available | 
| PREFERENCE_ERROR_IO_ERROR | Internal I/O Error | 
| int preference_remove_all | ( | void | ) | 
Removes all key-value pairs from the preference.
0 on success, otherwise a negative error value | PREFERENCE_ERROR_NONE | Successful | 
| PREFERENCE_ERROR_OUT_OF_MEMORY | Out of memory | 
| PREFERENCE_ERROR_IO_ERROR | Internal I/O Error | 
| int preference_set_boolean | ( | const char * | key, | 
| bool | value | ||
| ) | 
Sets a boolean value in the preference.
| [in] | key | The name of the key to modify | 
| [in] | value | The new boolean value associated with the given key  | 
0 on success, otherwise a negative error value | PREFERENCE_ERROR_NONE | Successful | 
| PREFERENCE_ERROR_INVALID_PARAMETER | Invalid parameter | 
| PREFERENCE_ERROR_OUT_OF_MEMORY | Out of memory | 
| PREFERENCE_ERROR_IO_ERROR | Internal I/O Error | 
| int preference_set_changed_cb | ( | const char * | key, | 
| preference_changed_cb | callback, | ||
| void * | user_data | ||
| ) | 
Registers a callback function to be invoked when value of the given key in the preference changes.
| [in] | key | The name of the key to monitor | 
| [in] | callback | The callback function to register | 
| [in] | user_data | The user data to be passed to the callback function | 
0 on success, otherwise a negative error value | PREFERENCE_ERROR_NONE | Successful | 
| PREFERENCE_ERROR_INVALID_PARAMETER | Invalid parameter | 
| PREFERENCE_ERROR_OUT_OF_MEMORY | Out of memory | 
| PREFERENCE_ERROR_NO_KEY | Required key not available | 
| PREFERENCE_ERROR_IO_ERROR | Internal I/O Error | 
| int preference_set_double | ( | const char * | key, | 
| double | value | ||
| ) | 
Sets a double value in the preference.
| [in] | key | The name of the key to modify | 
| [in] | value | The new double value associated with the given key  | 
0 on success, otherwise a negative error value | PREFERENCE_ERROR_NONE | Successful | 
| PREFERENCE_ERROR_INVALID_PARAMETER | Invalid parameter | 
| PREFERENCE_ERROR_OUT_OF_MEMORY | Out of memory | 
| PREFERENCE_ERROR_IO_ERROR | Internal I/O Error | 
| int preference_set_int | ( | const char * | key, | 
| int | value | ||
| ) | 
Sets an integer value in the preference.
| [in] | key | The name of the key to modify | 
| [in] | value | The new int value for the given key  | 
0 on success, otherwise a negative error value | PREFERENCE_ERROR_NONE | Successful | 
| PREFERENCE_ERROR_INVALID_PARAMETER | Invalid parameter | 
| PREFERENCE_ERROR_OUT_OF_MEMORY | Out of memory | 
| PREFERENCE_ERROR_IO_ERROR | Internal I/O Error | 
| int preference_set_string | ( | const char * | key, | 
| const char * | value | ||
| ) | 
Sets a string value in the preference.
It makes a deep copy of the added string value.
| [in] | key | The name of the key to modify | 
| [in] | value | The new string value associated with the given key  | 
0 on success, otherwise a negative error value | PREFERENCE_ERROR_NONE | Successful | 
| PREFERENCE_ERROR_INVALID_PARAMETER | Invalid parameter | 
| PREFERENCE_ERROR_OUT_OF_MEMORY | Out of memory | 
| PREFERENCE_ERROR_IO_ERROR | Internal I/O Error | 
| int preference_unset_changed_cb | ( | const char * | key | ) | 
Unregisters the callback function.
| [in] | key | The name of the key to monitor | 
0 on success, otherwise a negative error value | PREFERENCE_ERROR_NONE | Successful | 
| PREFERENCE_ERROR_INVALID_PARAMETER | Invalid parameter | 
| PREFERENCE_ERROR_OUT_OF_MEMORY | Out of memory | 
| PREFERENCE_ERROR_NO_KEY | Required key not available | 
| PREFERENCE_ERROR_IO_ERROR | Internal I/O Error |