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]
|
6月前
|
JavaScript 前端开发 Android开发
Android AgentWeb WebView 与js交互总结
Android AgentWeb WebView 与js交互总结
182 0
|
JavaScript 前端开发 Android开发
JS(Javascript)调用Android原生方法三步走
JS(Javascript)调用Android原生方法三步走
462 0
|
JavaScript Android开发 iOS开发
html通过js调用ios或android代码
html通过js调用ios或android代码
130 0
|
移动开发 JavaScript Android开发
js调用ios和android方法使用总结
js调动原生登录方法 使用场景,点击一个按钮,如果没有登录,则调用原生登录窗口,原生登录成功以后把usercode赋值给h5页面
612 0
|
JavaScript Android开发 iOS开发
html通过js调用ios或android代码
html通过js调用ios或android代码
49 0
|
JavaScript Android开发
Android JS 交互=坑
Android JS 交互=坑
99 0
|
JavaScript Android开发 iOS开发
html通过js调用ios或android代码
html通过js调用ios或android代码
|
JavaScript Android开发
关于Android JS与原生的交互
有两种方法,我们知道,Android使用WebView加载页面是可以拦截到页面的url的,既然可以拦截到url,那就可以对url进行解析处理,判断后走不同的业务逻辑,比如判断url是否是一个pdf页面,如果是,就跳转页面去加载pdf等。
185 0
|
JavaScript Android开发
Android:WebView与js交互方式
通过WebView的addJavascriptInterface()进行对象映射 将JS代码javascript.html格式放到src/main/assets文件夹里 javascript.html
283 0