前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SAP offline plugin简介

SAP offline plugin简介

作者头像
Jerry Wang
发布2019-12-12 14:45:32
4910
发布2019-12-12 14:45:32
举报

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.

Custom OData httpclient

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();

clipboard1
clipboard1

plugin.xml

clipboard2
clipboard2

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.

config
config

JavaScript interface

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.

/**

  • Implements the API of ExposedJsApi.java, but uses prompt() to communicate.
  • This is used pre-JellyBean, where addJavascriptInterface() is disabled. */ Whether you distribute a plugin as Java file or as a jar file of its own, the plugin must be specified in your Cordova-Android application’sres/xml/config.xml file. See Application Plugins for more information on how to use the plugin.xml file to inject this feature element:
代码语言:javascript
复制
<feature name="<service_name>">
    <param name="android-package" value="<full_name_including_namespace>" />
</feature>
image2016-8-4 11_24_30
image2016-8-4 11_24_30

Plugins should use the initialize method for their start-up logic.

代码语言:javascript
复制
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);
    // your init code here
}
image2016-8-4 11_20_32
image2016-8-4 11_20_32

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:

代码语言:javascript
复制
@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.
}

Javascript bridge

Offline store

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.

DBMS
DBMS
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-12-11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Custom OData httpclient
  • plugin.xml
  • JavaScript interface
  • Javascript bridge
  • Offline store
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档