Settings¶
Get Application-Level Settings From SAP Mobile Services¶
final Settings settings = new Settings();
// Must be invoked from UI thread
settings.load(Settings.SettingTarget.APPLICATION,
Settings.KeyPath.MOBILESERVICES,
new Settings.CallbackListener() {
// Executes on UI thread
@Override
public void onSuccess(@NonNull JSONObject settingsData) {
try {
int valueForPasswordPolicyTimeout = settingsData.getJSONObject("settingsExchange")
.getJSONObject("passwordPolicy")
.getInt("passwordPolicyLockTimeout");
sLogger.debug("Passcode timeout: {}", valueForPasswordPolicyTimeout);
} catch (JSONException ex) {
//Most likely reason is invalid root key specified
sLogger.error("Unexpected settings data: {}", settingsData.toString());
}
}
// Executes on UI thread
@Override
public void onError(@NonNull Throwable ex) {
// com.sap.cloud.mobile.foundation.networking.HttpException
if (ex instanceof HttpException) {
sLogger.error("Settings load failed. Message: {}, http code: {}",
((HttpException) ex).message(), ((HttpException) ex).code());
} else {
sLogger.error("Request failed: {}", ex.getMessage());
}
}
});
val settings = Settings()
// Must be invoked from UI thread
settings.load(Settings.SettingTarget.APPLICATION,
Settings.KeyPath.MOBILESERVICES,
object : Settings.CallbackListener {
// Executes on UI thread
override fun onSuccess(settingsData: JSONObject) {
try {
val valueForPasswordPolicyTimeout = settingsData.getJSONObject("settingsExchange")
.getJSONObject("passwordPolicy")
.getInt("passwordPolicyLockTimeout")
sLogger.debug("Passcode timeout: {}", valueForPasswordPolicyTimeout)
} catch (ex: JSONException) {
//Most likely reason is invalid root key specified
sLogger.error("Unexpected settings data: {}", settingsData.toString())
}
}
// Executes on UI thread
override fun onError(ex: Throwable) {
// com.sap.cloud.mobile.foundation.networking.HttpException
if (ex is HttpException) {
sLogger.error("Settings load failed. Message: {}, http code: {}",
ex.message(), ex.code())
} else {
sLogger.error("Request failed: {}", ex.message)
}
}
})
Store User Settings on SAP Mobile Services¶
final Settings settings = new Settings();
// Must be invoked from UI thread
settings.store(Settings.SettingTarget.USER,
Settings.KeyPath.LOGSETTINGS,
new JSONObject().put("logLevel", "TRACE"),
new Settings.CallbackListener() {
// Executes on UI thread
@Override
public void onSuccess(@NonNull JSONObject settingsData) {
sLogger.debug("Settings stored.");
}
// Executes on UI thread
@Override
public void onError(@NonNull Throwable ex) {
// com.sap.cloud.mobile.foundation.networking.HttpException
if (ex instanceof HttpException) {
sLogger.error("Settings store failed. Message: {}, http code: {}",
((HttpException) ex).message(), ((HttpException) ex).code());
} else {
sLogger.error("Request failed: {}", ex.getMessage());
}
}
}
);
val settings = Settings()
// Must be invoked from UI thread
settings.store(Settings.SettingTarget.USER,
Settings.KeyPath.LOGSETTINGS,
JSONObject().put("logLevel", "TRACE"),
object : Settings.CallbackListener {
// Executes on UI thread
override fun onSuccess(settingsData: JSONObject) {
sLogger.debug("Settings stored.")
}
// Executes on UI thread
override fun onError(ex: Throwable) {
// com.sap.cloud.mobile.foundation.networking.HttpException
if (ex is HttpException) {
sLogger.error("Settings store failed. Message: {}, http code: {}",
ex.message(), ex.code())
} else {
sLogger.error("Request failed: {}", ex.message)
}
}
}
)
Last update: April 14, 2021