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的原创文章,请关注公众号"汪子熙":
相关推荐
总结来说,"offline-android-gradle-plugin-preview.zip"提供的预览版插件是Android开发者在离线环境下的重要资源,它涉及到了Android构建流程中的各个关键环节,包括依赖管理、代码优化、资源处理、多模块构建等多...
在Android平台上实现离线语音合成是一项实用且技术含量较高的任务,尤其对于那些希望在无网络环境下仍然能够提供语音服务的应用来说。本教程将详细介绍如何利用科大讯飞提供的语记SDK来实现这一功能,并附带源代码供...
Android studio离线组件最新版本的 Google Maven 依赖项offline-gmaven-stable,文件分割成 三个 压缩包,必须集齐 三个 文件后才能一起解压一起使用: Android studio离线组件offline-gmaven-stable.part1.rar ...
Android studio离线组件最新版本的 Google Maven 依赖项offline-gmaven-stable,文件分割成 三个 压缩包,必须集齐 三个 文件后才能一起解压一起使用: Android studio离线组件offline-gmaven-stable.part1.rar ...
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离线组件最新版本的 Google Maven 依赖项offline-gmaven-stable,文件分割成 三个 压缩包,必须集齐 三个 文件后才能一起解压一起使用: Android studio离线组件offline-gmaven-stable.part1.rar ...
一个Chrome浏览器插件Android Offline Doc,可以离线阅读Android SDK本地文档 使用: 1. 解压到一个目录 2. 打开Chrome,"Tools" -- "Extension",勾选"Developer mode" 3. 点击"Load unpacked extension"按钮,找到...
4. **本地化Google Maps API**:将Google Maps API进行本地化,意味着开发者需要创建一个本地服务器,存储地图图片和必要的地理数据,然后通过JavaScript代码来调用这些本地资源,而不是实时向Google服务器请求。...
科大讯飞离线TTS语音朗读引擎 windws sdk ,c代码 封装成dll使用C#调用 由于讯飞的离线sdk与appid 是捆绑的,所以需要在讯飞开发平台生成自己的应用和appid 并下载 windows 离线语音合成 sdk ,能够运行 demo 里的 ...
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 ...
作为一款基于JavaScript的Chrome插件,"android_offline_doc_plugin"利用了Chrome浏览器的扩展开发框架。它在用户安装并启用插件后,会在访问特定的Android离线文档页面时自动生效。插件的核心是JavaScript代码,这...
2. **百度地图JavaScript库**:这个压缩包可能包含了百度地图API V3.0的离线版本,使得在没有网络连接的情况下,JavaScript代码仍能调用这些API来加载和操作地图。 3. **示例代码或配置文件**:为了帮助开发者更好...
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应用源码。这些源码涵盖了多种Android开发中的核心功能和常见应用场景,是深入理解Android开发...
"解决android studio加载慢的插件.zip"这个压缩包可能包含了一些优化Android Studio性能的插件或者指导文档,旨在帮助用户改善这一状况。 Android Studio是Google为Android应用开发提供的集成开发环境(IDE),基于...
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 ...
开发者可以通过调用SDK提供的API接口,将人脸识别功能轻松集成到Java项目中。通常包括注册SDK、加载模型、初始化人脸检测器、执行人脸识别和处理返回结果等步骤。 7. **应用场景** 百度人脸识别SDK广泛应用于安全...
The NETWORKING module provides a separation from the network tier from the rest of the project while also providing offline support capabilities. Usage Import the module as alibrary in your project ...
【Emma Java代码覆盖率统计】 Emma 是一款开源的 Java 代码覆盖率工具,专为评估和报告 Java 代码的测试覆盖率而设计。它适用于各种规模的项目,从小型项目到大型企业级应用,都能提供准确的覆盖率数据。Emma 提供...