System Settings: Getting Miscellaneous System Settings and Preferences
This tutorial demonstrates how you can manage and monitor system settings.
Warm-up
Become familiar with the System Settings API basics by learning about:
-
Managing System Settings
Obtain, set, and track system settings.
Managing System Settings
To manage system settings, which provide access to system variables:
-
To use the system settings-related features of the System Settings API (in mobile and wearable applications), include the <system_settings.h> header file in your application:
#include <system_settings.h>
-
Define auxiliary structures:
struct _ret_type_define { system_settings_key_e key; int returns; }; typedef enum { _RET_BOO = 0, _RET_INT, _RET_STRING } _SYSTEM_SETTINGS_TYPES; struct _ret_type_define _ret_type[] = { { SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, _RET_STRING }, { SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, _RET_STRING }, { SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, _RET_STRING }, { SYSTEM_SETTINGS_KEY_FONT_SIZE, _RET_INT }, { SYSTEM_SETTINGS_KEY_FONT_TYPE, _RET_STRING }, { SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, _RET_BOOL }, { // Others } };
static const char *_info_key[SYS_INFO_COUNT]= { "SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE", "SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN", "SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN", "SYSTEM_SETTINGS_KEY_FONT_SIZE", "SYSTEM_SETTINGS_KEY_FONT_TYPE", "SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION", // Others };
-
Get the setting data.
The available settings are defined in the system_settings_key_e enumerator (in mobile and wearable applications).
Read the data using the following functions, according to the data type of the value you want to read:
- int system_settings_get_value_int (system_settings_key_e key, int *value)
- int system_settings_get_value_bool (system_settings_key_e key, bool *value)
- int system_settings_get_value_double (system_settings_key_e key, double *value)
- int system_settings_get_value_string (system_settings_key_e key, char **value)
#define SYS_INFO_COUNT 6 int i; for (i = 0; i<SYS_INFO_COUNT; i++) { dlog_print(DLOG_ERROR,LOG_TAG,"%d- System_settings: %s : ", i, _info_key[_ret_type[i].key]); if (_ret_type[i].returns==_RET_BOOL) { system_settings_get_value_bool(_ret_type[i].key, &_bool_ret); dlog_print(DLOG_ERROR, LOG_TAG, "%d", _bool_ret); } else if (_ret_type[i].returns==_RET_INT) { system_settings_get_value_int (_ret_type[i].key, &_int_ret); dlog_print(DLOG_ERROR, LOG_TAG, "%d", _int_ret); } else if (_ret_type[i].returns==_RET_STRING) { system_settings_get_value_string(_ret_type[i].key, &_string_ret); dlog_print(DLOG_ERROR, LOG_TAG, "%s", _string_ret); free(_string_ret); } else if (_ret_type[i].returns==_RET_DOUBLE) { system_settings_get_value_double(_ret_type[i].key, &_double_ret); dlog_print(DLOG_ERROR, LOG_TAG, "%f", _double_ret); } else dlog_print(DLOG_ERROR, LOG_TAG, "Undefined return type"); }
-
Track changes in the settings.
-
To track changes in the value of any system setting, set a callback function with the proper key.
The SYSTEM_SETTINGS_KEY_DEFAULT_FONT_TYPE setting does not support the callback function, so you must iterate through the SYS_INFO_COUNT-1 records.
for (i = 0; i<SYS_INFO_COUNT-1; i++) { system_settings_set_changed_cb(_ret_type[i].key, _system_settings_changed_cb, 0); }
-
Define the callback which is invoked after each change. The system_settings_key_e key refers to the key which has changed.
static void _system_settings_changed_cb(system_settings_key_e key, void *user_data) { dlog_print(DLOG_ERROR, LOG_TAG, "Runtime Info changed: %s", _info_key[key]); }
-
When they are no longer needed, unregister the callbacks:
for (i = 0; i<SYS_INFO_COUNT-1; i++) { system_settings_unset_changed_cb(_ret_type[i].key, _system_settings_changed_cb, 0); }
-