bfgSettings Class
Stores settings to disk automatically so that other libraries can use keys to retrieve them. More...
Static Public Member Functions | |
static Object | get (@NonNull final String key) |
Returns the object associated with the key, or null if the key was not found. More... | |
static Object | get (@NonNull final String key, @Nullable final Object withDefault) |
Returns the object associated with the key, or null if the key was not found. More... | |
static boolean | getBoolean (@NonNull final String key, @Nullable final boolean withDefault) |
This version of the get() method lets the caller avoid having to do casting in order to get at the actual boolean value. More... | |
static Vector< Hashtable< String, Object > > | getDictionaryArray (@NonNull final String key, @Nullable final Vector< Hashtable< String, Object > > withDefault) |
Get an array of JSON dictionary values. More... | |
static double | getDouble (@NonNull final String key, final double withDefault) |
This version of the get() method lets the caller avoid having to do casting in order to get at the actual double value. More... | |
static int | getInteger (@NonNull final String key, final int withDefault) |
This version of the get() method lets the caller avoid having to do casting in order to get at the actual integer value. More... | |
static long | getLong (@NonNull final String key, final long withDefault) |
This version of the get() method lets the caller avoid having to do casting in order to get at the actual long value. More... | |
static String | getString (@NonNull final String key, @Nullable final String withDefault) |
This version of the get() method lets the caller avoid having to do casting in order to get at the string value. More... | |
static Vector< String > | getStringVector (@NonNull final String key, @Nullable final Vector< String > withDefault) |
Get a string array from Settings. More... | |
static void | initializeWithContext (@NonNull final Context context) |
Initialize the bfgSettings class in cases where the BFG SDK is not initialized. More... | |
static boolean | isInitialized () |
Determine if bfgSettings has been initialized yet and is ready for use. More... | |
static void | set (@NonNull final String key, @Nullable final Serializable value) |
Save a generic object. More... | |
static void | write () |
Forces a write of the settings to disk. More... | |
static String | writeToJSON (@NonNull final Map< String, Object > table) |
Converts the key-value pairs in a hash table into a JSON formatted string. More... | |
Static Public Attributes | |
static final String | BFG_SETTING_GAME_SERVICE_TOKEN = "game_service_token" |
Since 6.1. | |
static final String | BFG_TOAST_ENABLED = "bfg_toast_enabled" |
Since 6.2. | |
Detailed Description
Stores settings to disk automatically so that other libraries can use keys to retrieve them. Developers can use this class to store settings used in their own libraries.
NOTE: This class requires a working context in order to function as expected. In cases where the SDK is not yet initialized (e.g., accessing settings as a result of a push notification or accessing before initializing the SDK), you MUST call:
NOTE: This class requires a working context in order to function as expected. In cases where the SDK is not yet initialized (e.g., accessing settings as a result of a push notification or accessing before initializing the SDK), you MUST call:
initializeWithContext(Context)
before attempting to access any settings using this class.If you are using these APIs, you can become an observer for the following event: - NOTIFICATION_BFGSETTING_CHANGED - When a setting is changed, this notification is sent. The name and value of the property are also sent.
Member Function Documentation
◆ get() [1/2]
| inlinestatic |
Returns the object associated with the key, or null if the key was not found. Returned objects can be Strings or primitive type wrappers. If the key is associated with an object containing members or even an empty object, the returned object will be of type JSONObject. If the key is associated with an array, the returned object will be of type JSONArray.
- Parameters
key String whose associated object is to be returned.
- Returns
- The object associated with the key or null.
◆ get() [2/2]
| inlinestatic |
Returns the object associated with the key, or null if the key was not found. Returned objects can be Strings or primitive type wrappers. If the key is associated with an object containing members or even an empty object, the returned object will be of type JSONObject. If the key is associated with an array, the returned object will be of type JSONArray.
- Parameters
key String whose associated object is to be returned. withDefault Object to return if the key is not found.
- Returns
- The object associated with the key or the withDefault value if it does not exist.
◆ getBoolean()
| inlinestatic |
This version of the get() method lets the caller avoid having to do casting in order to get at the actual boolean value.
- Parameters
key String whose associated object is to be returned. withDefault Boolean value to return if the key is not found.
- Returns
- Value as a primitive boolean. TRUE if boolean TRUE or Integer non-zero (e.g., 0/1 for FALSE/TRUE) NOTE: Integer 0/1 is supported for compatibility with older code that stored booleans as 0/1 integers.
◆ getDictionaryArray()
| inlinestatic |
Get an array of JSON dictionary values.
- Parameters
key withDefault
- Returns
- Array of dictionaries associated with the key or the withDefault value if it does not exist.
◆ getDouble()
| inlinestatic |
This version of the get() method lets the caller avoid having to do casting in order to get at the actual double value.
- Parameters
key String whose associated object is to be returned. withDefault Integer value to return if the key is not found.
- Returns
- Value as a primitive double.
◆ getInteger()
| inlinestatic |
This version of the get() method lets the caller avoid having to do casting in order to get at the actual integer value.
- Parameters
key String whose associated object is to be returned. withDefault Integer value to return if the key is not found.
- Returns
- Value as a primitive integer.
◆ getLong()
| inlinestatic |
This version of the get() method lets the caller avoid having to do casting in order to get at the actual long value.
- Parameters
key String whose associated object is to be returned. withDefault Long value to return if the key is not found.
- Returns
- Value as a primitive long.
◆ getString()
| inlinestatic |
This version of the get() method lets the caller avoid having to do casting in order to get at the string value.
- Parameters
key String whose associated object is to be returned. withDefault String to return if the key is not found.
- Returns
- Value as a string object or the withDefault value if it does not exist.
◆ getStringVector()
| inlinestatic |
Get a string array from Settings.
- Parameters
key withDefault
- Returns
- Vector associated with the key or the withDefault value if it does not exist.
◆ initializeWithContext()
| inlinestatic |
Initialize the bfgSettings class in cases where the BFG SDK is not initialized. This is useful for cases when one needs to access bfgSettings and the SDK is not yet running. For example, accessing this class after receiving a push notification or an intent that's broadcast, this must be called before attempting to call any other bfgSettings methods.
- Parameters
context - valid context used to access filesystem
◆ isInitialized()
| inlinestatic |
Determine if bfgSettings has been initialized yet and is ready for use.
- Returns
- TRUE if initialized.
◆ set()
| inlinestatic |
Save a generic object.
- Parameters
key Name of object being saved value Object to save. NOTE: value must be a standard object, such as String, HashMap, int, etc. and not a custom object or the object will not be saved across cold starts.
◆ write()
| inlinestatic |
Forces a write of the settings to disk.
- Deprecated:\n No longer needed. All changes to data are automatically written to disk
◆ writeToJSON()
| inlinestatic |
Converts the key-value pairs in a hash table into a JSON formatted string. The hash table values can be an instance of any of the following classes: String, Number, Hashtable<String, Object> or Vector<String>
- Parameters
table HashMap of Settings key-value pairs.
- Returns
- Table content in readable String format.
- Deprecated:\n