phonegap跳转Activity android插件调用原生

Phonegap的插件 调用本地的Activity

查看我上一篇插件开发的文章:

本节主要记录调用Activity的方式; 并提供 插件Demo下载

插件开发4个步骤:

1 在assents 目录下的 cordova-plugins.js文件添加配置

2 在assets/www 的 plugin目录下编写javascript接口

3 在res/xml 目录下配置 config.xml 文件

4 在src目录下编写java文件 实现跳转

工程:

1 配置 cordova _plugins.js 文件

首先给大家展示cordova _plugins.js 文件:

cordova.define(‘cordova/plugin_list’, function(require, exports, module) {module.exports = [{"file": "plugins/org.apache.cordova.camera/www/CameraConstants.js","id": "org.apache.cordova.camera.Camera","clobbers": ["Camera"]},{"file": "plugins/org.apache.cordova.camera/www/CameraPopoverOptions.js","id": "org.apache.cordova.camera.CameraPopoverOptions","clobbers": ["CameraPopoverOptions"]},{"file": "plugins/org.apache.cordova.camera/www/Camera.js","id": "org.apache.cordova.camera.camera","clobbers": ["navigator.camera"]},{"file": "plugins/org.apache.cordova.camera/www/CameraPopoverHandle.js","id": "org.apache.cordova.camera.CameraPopoverHandle","clobbers": ["CameraPopoverHandle"]},{"file": "plugins/org.apache.cordova.dialogs/www/notification.js","id": "org.apache.cordova.dialogs.notification","merges": ["navigator.notification"]},{"file": "plugins/org.apache.cordova.dialogs/www/android/notification.js","id": "org.apache.cordova.dialogs.notification_android","merges": ["navigator.notification"]},{"file": "plugins/org.apache.cordova.vibration/www/vibration.js","id": "org.apache.cordova.vibration.notification","merges": ["navigator.notification"]},{"file": "plugins/intent.js","id": "org.apache.cordova.intent","merges": ["navigator.intent"]},];module.exports.metadata = // TOP OF METADATA{"org.apache.cordova.camera": "0.2.7","org.apache.cordova.dialogs": "0.2.6","org.apache.cordova.vibration": "0.3.7","org.apache.cordova.intent" :"0.0.1",}// BOTTOM OF METADATA});

2 在plugin目录下编写javascript接口

贴上intent.js的接口代码

cordova.define("org.apache.cordova.intent", function(require, exports, module) { var exec = require(‘cordova/exec’);module.exports = {/*** 一共5个参数第一个 :成功会掉第二个 :失败回调第三个 :将要调用的类的配置名字(在config.xml中配置 稍后在下面会讲解)第四个 :调用的方法名(一个类里可能有多个方法 靠这个参数区分)第五个 :传递的参数 以json的格式*/demo: function(mills) {exec(function(winParam){alert(winParam);}, null, "Demo", "intent", [mills]);},};});

Demo中成功返回 会弹出一个Alert();

在javascript中的 调用语句是

navigator.intent.demo(1);

贴上整的javascript

<!DOCTYPE html><html> <head><title>Notification Example</title> <script type="text/javascript" charset="utf-8" src="cordova.js"></script><script type="text/javascript" charset="utf-8">// Wait for device API libraries to load//document.addEventListener("deviceready", onDeviceReady, false);// device APIs are available//function onDeviceReady() {// Empty}// Show a custom alert// native的 Dialog 对话框function showAlert() {navigator.notification.alert(‘You are the winner!’, // message’Game Over’,// title’Done’// buttonName); }// Beep three times// 响铃3声function playBeep() {navigator.notification.beep(3); }// Vibrate for 2 seconds// 振动function vibrate() {navigator.notification.vibrate(100000); }//跳转function intent() {navigator.intent.demo(1);}</script></head><body><p><a href="#" onclick="showAlert(); return false;">Show Alert</a></p><p><a href="#" onclick="playBeep(); return false;">Play Beep</a></p><p><a href="#" onclick="vibrate(); return false;">Vibrate</a></p><p><a href="#" onclick="intent(); return false;">Html跳转到android界面</a></p></body></html>

<3> 在res/xml 目录下配置 config.xml 文件

便是不再存在着任何我曾经对你有过的希望。

phonegap跳转Activity android插件调用原生

相关文章:

你感兴趣的文章:

标签云: