Application Preferences (New in SP04)
This plugin provides a native settings page for an app. It was developed to be used in the SAP Fiori Client. The settings screen can be shown by calling
The settings are specified by calling
sap.AppPreferences.configurePreferencesScreen(preferencesJSON, successCallback, errorCallback);
where preferencesJSON describes the settings to be shown.
The values can be accessed and modified programmatically by calling
sap.AppPreferences.getPreferenceValue(key, successCallback, errorCallback);
sap.AppPreferences.setPreferenceValue(key, value, successCallback, errorCallback);
For additional details on the apppreferences plugin see C:\SAP\MobileSDK3\KapselSDK\docs\api\sap.AppPreferences.html or Using the AppPreferences Plugin.
The following steps will demonstrate an example of using this plugin.
- Create the project and add the AppPreferences plugin.
cordova create C:\Kapsel_Projects\AppPreferencesDemo com.mycompany.apppreferences AppPreferencesDemo cd C:\Kapsel_Projects\AppPreferencesDemo cordova platform add android cordova plugin add kapsel-plugin-apppreferences --searchpath %KAPSEL_HOME%/plugins cordova create ~/Documents/Kapsel_Projects/AppPreferencesDemo com.mycompany.apppreferences AppPreferencesDemo cd ~/Documents/Kapsel_Projects/AppPreferencesDemo cordova platform add ios cordova plugin add kapsel-plugin-apppreferences --searchpath $KAPSEL_HOME/plugins
- Replace www\index.html with the contents of index.html.
Note (Android specific), save the file validation.html to www\validation.html. If the setting webapppath in the preferencesJSON is incorrect, the validation function will not work.
- On Android, optionally choose a different theme for the settings dialog by modifying AndroidManifest.xml and changing minSdkVersion to 11 and the theme for PrefsActivity from Theme.Black.NoTitleBar to Theme.Holo.Light. See also Android Themes.
- Prepare, build and deploy the app with the following commands.
cordova run android or cordova run ios
Note, in addition to the four types which are edittext, switch, checkbox and list there is also a button type that when pressed simply triggers the validation function on Android.
On Android, if an alert() call is made following the call to sap.AppPreferences.showPreferencesScreen or in the successcallback method, the validation function will not be called in versions of Android less than 4.4. A workaround for this is to add the plugin org.apache.cordova.dialogs and then to use navigator.notification.alert() instead of alert().
- This plugin is mainly used with the SAP Fiori Client and has some bugs/limitations. The following are some of the issues seen while working with the above sample.
BCP 1482004286. On iOS, each setting must have a category.
BCP 1482005324. Missing support for switch and checkbox on iOS.
BCP 1482005323. Readonly attribute does not appear to work with a list type on Android or iOS.
BCP 1482005322. Defaultvalue attribute does not work for edittext types on iOS.