cordova.js启动

src/android/platform.js 平台启动处理

源码:

Js 代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// file: src/android/platform.js
define("cordova/platform", function(require, exports, module) {
module.exports = {
id: 'android',
// 平台启动处理(各个平台处理都不一样,比如ios就只需要触发onNativeReady)
bootstrap: function() {
var channel = require('cordova/channel'),
cordova = require('cordova'),
exec = require('cordova/exec'),
modulemapper = require('cordova/modulemapper');
// 把exec()的执行从WebCore线程变到UI线程上来
// 后台PluginManager初始化的时候默认添加了一个'PluginManager的插件
exec(null, null, 'PluginManager', 'startup', []);
// 触发onNativeReady事件通道,告诉JS本地代码已经完成
channel.onNativeReady.fire();
// app插件。现在没有被单独抽出去,没找到合适的地方。
modulemapper.clobbers('cordova/plugin/android/app', 'navigator.app');
// 给返回按钮注意个监听器
var backButtonChannel = cordova.addDocumentEventHandler('backbutton');
backButtonChannel.onHasSubscribersChange = function() {
// 如果只为返回按钮定义了1个事件监听器的话,通知后台覆盖默认行为
exec(null, null, "App", "overrideBackbutton", [this.numHandlers == 1]);
};
// 添加菜单和搜素的事件监听
cordova.addDocumentEventHandler('menubutton');
cordova.addDocumentEventHandler('searchbutton');
// 启动完成后,告诉本地代码显示WebView
channel.onCordovaReady.subscribe(function() {
exec(null, null, "App", "show", []);
});
}
};
});

联系我们

邮箱 626512443@qq.com
电话 18611320371(微信)
QQ群 235681453

Copyright © 2015-2024

备案号:京ICP备15003423号-3