“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
<3> 在res/xml 目录下配置 config.xml 文件
config.xml配置 加上 如下
feature的name属性 非常重要
name必须是步骤< 4 >中 function中调用的类名
value属性指定插件在src目录下的java文件 (命名空间)
前3个步骤 参考上一章 phonegap插件开发
这里主要描述
<4> 编写phonegap的java插件类 调用本地的activity
首先继承CordovaPlugin
重写execute方法 execute返回值为true时 此插件可用;返回为false时 此插件失效
在插件类当中获取 this 跳转
Intent intent = new Intent(cordova.getActivity(), DemoActivity.class);
cordova.startActivityForResult((CordovaPlugin) this,intent, 200);
如果使用
cordova.getActivity().startActivityForResult(intent,200);
被调用的Activity 在 setResult之后;
并不会返回到当前的插件中 它将返回到的webView的CordovaActivity当中 ,
Plugin_intent 类的 onActivityResult将收不到消息 ;
我查看源码后得知 cordova这个是CordovaInterface类型的 已由CordovaPlugin实现
在CordovaInterface当中找到了
/**
-
Launch an activity for which you would like a result when it finished. When this activity exits,
-
your onActivityResult() method will be called.
-
@param command The command object
-
@param intent The intent to start
-
@param requestCode The request code that is passed to callback to identify the activity
*/
abstract public void startActivityForResult(CordovaPlugin command, Intent intent, int requestCode);
完整实例
package plugins;
最后
在这里我和身边一些朋友特意整理了一份快速进阶为Android高级工程师的系统且全面的学习资料。涵盖了Android初级——Android高级架构师进阶必备的一些学习技能。
附上:我们之前因为秋招收集的二十套一二线互联网公司Android面试真题(含BAT、小米、华为、美团、滴滴)和我自己整理Android复习笔记(包含Android基础知识点、Android扩展知识点、Android源码解析、设计模式汇总、Gradle知识点、常见算法题汇总。)
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门,即可获取!
command, Intent intent, int requestCode);
完整实例
package plugins;
最后
在这里我和身边一些朋友特意整理了一份快速进阶为Android高级工程师的系统且全面的学习资料。涵盖了Android初级——Android高级架构师进阶必备的一些学习技能。
附上:我们之前因为秋招收集的二十套一二线互联网公司Android面试真题(含BAT、小米、华为、美团、滴滴)和我自己整理Android复习笔记(包含Android基础知识点、Android扩展知识点、Android源码解析、设计模式汇总、Gradle知识点、常见算法题汇总。)
[外链图片转存中…(img-OZj8wBdB-1715589307724)]
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门,即可获取!