SAP offline OData插件的JavaScript代码是如何调用到Android平台的Java代码的

简介: SAP offline OData插件的JavaScript代码是如何调用到Android平台的Java代码的

In previous blog How is OData request routed to Offline data store by OData offline plugin, according to comment, the Offline store will only be available once it is opened successfully. The open operation is done in Device native API, delegated in line 232.image.pngThe exec is available in exported module returned by require(‘cordova/exec’):image.pngAnd now I would like to understand how this exec is delegated to Java Native API in Android platform.

In folder android I have found this cordova.js:image.pnghe exec call is implemented by module defined in cordova.js:image.pngHere means the exec is implemented by androidExec:image.png

Key logic of androidExec implementationimage.png1) meaning of parameters success, fail, service, action, args


a. success & fail: JavaScript callback function after the specified Java API is called

b. service: Java class name

c. action: Java class method name

d. args: arguments passed from JavaScript to Java


(2) There are two technical approaches for communication from JavaScript to Java in Android platform, see them in constant jsToNativeModes:image.pngExample of JS_OBJECT, or called JavaScript interface:

Java code:image.pngIn JavaScript code, consume Java method getSomeString as below:image.png

Back to implementation of AndroidExec:image.pngit will again delegate the call to exec method of instance returned by nativeApiProvider.get().image.pngAgain look at implementation in nativeapiprovider.js, from the comment in line 21 we can know the currentApi returned by get comes from either ExposedJsApi.java or PromptBasedNativeAPI.image.pngThe ExposedJsApi.java could be found from this location:

image.pngIt is a Java interface with method exec defined:image.pngThe call from JavaScript to Java is done via prompt call:image.pngAnd the Java class SystemExposedJsApi implements the interface, delegates call to the instance of class CordovaBridge.image.pngCordovaBridge will delegate to PluginManager:image.pngPlugin manager first gets responsible plugin Java class by name, then perform the execute method of plugin.image.pngFor example this is OData offline plugin service class, in its execute method we can find there are lots of IF-ELSE branch to implement different offline operation.image.png






相关文章
|
消息中间件 移动开发 JavaScript
JSBridge:混合开发中的双向通信[Android、iOS&JavaScript]
WebView 是移动端中的一个控件,它为 JS 运行提供了一个沙箱环境。WebView 能够加载指定的 url,拦截页面发出的各种请求等各种页面控制功能,JSB 的实现就依赖于 WebView 暴露的各种接口。由于历史原因,IOS以8为分界,Android以4.4为分界,分为高低两个版本。而它们的区别在于 —— 回调。高版本可以通过执行回调拿到 JS 执行完毕的返回值,然后准确进行下一步操作。而低版本无法执行回调!Hybrid App 的核心。
JSBridge:混合开发中的双向通信[Android、iOS&JavaScript]
|
4月前
|
移动开发 JavaScript Java
Android与JS互相调
Android与JS互相调
|
4月前
|
Web App开发 JavaScript 前端开发
Android端使用WebView注入一段js代码实现js调用android
Android端使用WebView注入一段js代码实现js调用android
79 0
|
JavaScript 前端开发 Android开发
Android AgentWeb WebView 与js交互总结
Android AgentWeb WebView 与js交互总结
334 0
|
JavaScript 前端开发 Android开发
JS(Javascript)调用Android原生方法三步走
JS(Javascript)调用Android原生方法三步走
570 0
|
JavaScript Android开发 iOS开发
html通过js调用ios或android代码
html通过js调用ios或android代码
148 0
|
移动开发 JavaScript Android开发
js调用ios和android方法使用总结
js调动原生登录方法 使用场景,点击一个按钮,如果没有登录,则调用原生登录窗口,原生登录成功以后把usercode赋值给h5页面
657 0
|
JavaScript Android开发 iOS开发
html通过js调用ios或android代码
html通过js调用ios或android代码
61 0
|
JavaScript Android开发
Android JS 交互=坑
Android JS 交互=坑
114 0
|
JavaScript Android开发 iOS开发
html通过js调用ios或android代码
html通过js调用ios或android代码
116 0