The Offline OData plugin provides offline OData support to Kapsel applications. OData version 2.0 (OData V2) is supported. The plugin is supported for use with applications on the Android and iOS platforms. The plugin provides the client with the ability to define offline stores for an OData producer. When an offline store is first opened, it synchronizes with the OData producer. OData requests made against this plugin use the available open offline stores. The plugin uses the OData component from the SAP Mobile Platform SDK. from saphelp And there is a SCN document.
The Offline OData plugin provides a OData httpclient based on datajs, a cross-browser JavaScript library. Thehttpclient resolves requests with the Offline OData plugin if the service root of the request matches one of the open stores. The httpclient defaults to using the original OData.defaultHttpClient if the requests service root does not match any of the currently open stores. You must explicitly apply the custom httpclient in the JavaScript. sap.OData.applyHttpClient();
Plugins comprise a single JavaScript interface along with corresponding native code libraries for each supported platform. In essence this hides the various native code implementations behind a common JavaScript interface. The js-module tag specifies the path to the common JavaScript interface. The platform tag specifies a corresponding set of native code. The config-file tag encapsulates a feature tag that is injected into the platform-specific config.xml file to make the platform aware of the additional code library. The header-file and source-file tags specify the path to the library’s component files.
The plugin’s JavaScript interface uses the cordova.exec method as follows: exec(, , , , []);
This marshals a request from the WebView to the Android native side, effectively calling the action method on the service class, with additional arguments passed in the args array.
/**
<feature name="<service_name>">
<param name="android-package" value="<full_name_including_namespace>" />
</feature>
Plugins should use the initialize method for their start-up logic.
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
// your init code here
}
Plugins also have access to Android lifecycle events and can handle them by extending one of the provided methods (onResume, onDestroy, etc). Plugins with long-running requests, background activity such as media playback, listeners, or internal state should implement the onReset()method. It executes when the WebView navigates to a new page or refreshes, which reloads the JavaScript. A JavaScript call fires off a plugin request to the native side, and the corresponding Java plugin is mapped properly in the config.xml file, but what does the final Android Java Plugin class look like? Whatever is dispatched to the plugin with JavaScript’s exec function is passed into the plugin class’s execute method. Most execute implementations look like this:
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if ("beep".equals(action)) {
this.beep(args.getLong(0));
callbackContext.success();
return true;
}
return false; // Returning false results in a "MethodNotFound" error.
}
Once the offline store has been created, local changes made to it can be sent out via a call to store.flush(). The offline store can update its copy of the data by calling store.refresh().
The offline store files can be seen at \data\data\com.mycompany.offline2\files when running in an Android emulator as shown below.