`
JerryWang_SAP
  • 浏览: 1043471 次
  • 性别: Icon_minigender_1
  • 来自: 成都
文章分类
社区版块
存档分类
最新评论

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.

 

 

The exec is available in exported module returned by require(‘cordova/exec’):

 

 

And 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:

 

 

The exec call is implemented by module defined in cordova.js:

 

 

Here means the exec is implemented by androidExec:

 

 

Key logic of androidExec implementation

 

 

(1) 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:

 

 

Example of JS_OBJECT, or called JavaScript interface: Java code:

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class WebViewGUI extends Activity {
  WebView mWebView;
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mWebView = new WebView(this);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.addJavascriptInterface(new JavaScriptInterface(), "jsinterface");
    mWebView.loadUrl("file:///android_asset/www/index.html");
    setContentView(mWebView);
  }
  final class JavaScriptInterface {
    JavaScriptInterface () { }
    public String getSomeString() {
      return "string";
    }
  }
}

In JavaScript code, consume Java method getSomeString as below:

<script>
var String = window.jsinterface.getSomeString();
</script>

Back to implementation of AndroidExec:

var msgs = nativeApiProvider.get().exec(bridgeSecret, service, action, callbackId, argsJson);

it will again delegate the call to exec method of instance returned by nativeApiProvider.get().

 

 

Again 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.

 

 

The ExposedJsApi.java could be found from this location:

 

 

It is a Java interface with method exec defined:

 

 

The call from JavaScript to Java is done via prompt call:

 

 

And the Java class SystemExposedJsApi implements the interface, delegates call to the instance of class CordovaBridge.

 

 

CordovaBridge will delegate to PluginManager:

 

 

Plugin manager first gets responsible plugin Java class by name, then perform the execute method of plugin.

 

 

For 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.

 

 

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

0
1
分享到:
评论

相关推荐

    offline-android-gradle-plugin-preview.zip

    总结来说,"offline-android-gradle-plugin-preview.zip"提供的预览版插件是Android开发者在离线环境下的重要资源,它涉及到了Android构建流程中的各个关键环节,包括依赖管理、代码优化、资源处理、多模块构建等多...

    android调用讯飞语记实现在离线语音合成(含源代码)

    在Android平台上实现离线语音合成是一项实用且技术含量较高的任务,尤其对于那些希望在无网络环境下仍然能够提供语音服务的应用来说。本教程将详细介绍如何利用科大讯飞提供的语记SDK来实现这一功能,并附带源代码供...

    Android studio离线组件offline-gmaven-stable.part3.rar

    Android studio离线组件最新版本的 Google Maven 依赖项offline-gmaven-stable,文件分割成 三个 压缩包,必须集齐 三个 文件后才能一起解压一起使用: Android studio离线组件offline-gmaven-stable.part1.rar ...

    Android studio离线组件offline-gmaven-stable.part2.rar

    Android studio离线组件最新版本的 Google Maven 依赖项offline-gmaven-stable,文件分割成 三个 压缩包,必须集齐 三个 文件后才能一起解压一起使用: Android studio离线组件offline-gmaven-stable.part1.rar ...

    Android代码-Offline Calendar

    Offline Calendar Lets you add calendars to the Calendar app, which are not synchronized and are accessible only on the device itself. Create the calendar in this app and it will then be available in ...

    Android studio离线组件offline-gmaven-stable.part1.rar

    Android studio离线组件最新版本的 Google Maven 依赖项offline-gmaven-stable,文件分割成 三个 压缩包,必须集齐 三个 文件后才能一起解压一起使用: Android studio离线组件offline-gmaven-stable.part1.rar ...

    基于HTML5+css3+JavaScript+java+mysql 实现的管理系统.zip

    【Java】在后端,Java是一种常用的服务器端编程语言,其强类型、面向对象的特性使得代码结构清晰,易于维护。Spring框架常被用于构建Java Web应用,提供依赖注入(Dependency Injection)和面向切面编程(AOP),...

    android_offline_doc_plugin-master

    一个Chrome浏览器插件Android Offline Doc,可以离线阅读Android SDK本地文档 使用: 1. 解压到一个目录 2. 打开Chrome,"Tools" -- "Extension",勾选"Developer mode" 3. 点击"Load unpacked extension"按钮,找到...

    gmap.rar_GMAP_javascript_map_map javascript_map offline

    4. **本地化Google Maps API**:将Google Maps API进行本地化,意味着开发者需要创建一个本地服务器,存储地图图片和必要的地理数据,然后通过JavaScript代码来调用这些本地资源,而不是实时向Google服务器请求。...

    科大讯飞离线TTS语音朗读引擎 windws sdk ,c代码 封装成dll使用C#调用(unity插件)

    科大讯飞离线TTS语音朗读引擎 windws sdk ,c代码 封装成dll使用C#调用 由于讯飞的离线sdk与appid 是捆绑的,所以需要在讯飞开发平台生成自己的应用和appid 并下载 windows 离线语音合成 sdk ,能够运行 demo 里的 ...

    SAP PO/PI教程 Process Orchestration The Comprehensive Guide

    SAP Process Orchestration The Comprehensive Guide, 2nd Edition SAP流程编制综合指南 1 Introduction to SAP Process Orchestration 1.1 Historical Overview and Evolution 1.1.1 SAP Process Integration ...

    android_offline_doc_plugin:chrome插件,查看Android离线文档的时候屏蔽google资源请求

    作为一款基于JavaScript的Chrome插件,"android_offline_doc_plugin"利用了Chrome浏览器的扩展开发框架。它在用户安装并启用插件后,会在访问特定的Android离线文档页面时自动生效。插件的核心是JavaScript代码,这...

    baidumap_js_offline_V3.0

    2. **百度地图JavaScript库**:这个压缩包可能包含了百度地图API V3.0的离线版本,使得在没有网络连接的情况下,JavaScript代码仍能调用这些API来加载和操作地图。 3. **示例代码或配置文件**:为了帮助开发者更好...

    Building Android Apps with HTML, CSS, and JavaScript

    This hands-on book shows you how to use these open source web standards to design and build apps that can be adapted for any Android device — without having to use Java. You’ll learn how to create...

    收集整理的经典Android应用源码安卓实例源代码72个合集.zip

    这个压缩包文件“收集整理的经典Android应用源码安卓实例源代码72个合集.zip”包含了一系列用于学习和设计参考的Android应用源码。这些源码涵盖了多种Android开发中的核心功能和常见应用场景,是深入理解Android开发...

    解决android studio加载慢的插件.zip

    "解决android studio加载慢的插件.zip"这个压缩包可能包含了一些优化Android Studio性能的插件或者指导文档,旨在帮助用户改善这一状况。 Android Studio是Google为Android应用开发提供的集成开发环境(IDE),基于...

    百度人脸识别windows java离线sdk

    开发者可以通过调用SDK提供的API接口,将人脸识别功能轻松集成到Java项目中。通常包括注册SDK、加载模型、初始化人脸检测器、执行人脸识别和处理返回结果等步骤。 7. **应用场景** 百度人脸识别SDK广泛应用于安全...

    Bmap-offline_vue的api.js资源

    3. `js` - 可能包含了项目中的其他JavaScript文件,如Vue组件、业务逻辑代码等。 4. `maptile` - 这个目录非常重要,它很可能包含了离线地图的瓦片图片,这些瓦片被用于在没有网络连接时构建地图视图。 离线地图的...

    Building Android Apps with HTML,CSS,and.JavaScript(2nd,2012.01)

    This hands-on book shows you how to use these open source web standards to design and build apps that can be adapted for any Android device -- without having to use Java. You'll learn how to create ...

    WeEngine-Laster-Offline.zip_云柜官网代码_微云柜

    微云柜代码:放大版的信报箱柜子的管理,用户通过关注平台公众号,实现申请-购买-添加-使用柜子; 使用说明:安装完MeEngine-Laster-Offline后,通过管理员登陆,系统,模块,查找更多模块,微云柜,点击安装

Global site tag (gtag.js) - Google Analytics