|
楼主 |
发表于 2015-11-6 09:19:57
|
显示全部楼层
本帖最后由 ljgood09 于 2015-11-6 09:24 编辑
完整的plugin.xml- <?xml version="1.0" encoding="utf-8"?>
- <plugin id="cn.net.wenzhixin.cordova" version="0.0.1"
- xmlns="http://apache.org/cordova/ns/plugins/1.0"
- xmlns:android="http://schemas.android.com/apk/res/android">
- <name>ExtraInfo</name>
- <description>测试插件</description>
- <engines>
- <engine name="cordova" version="5.0.0" />
- </engines>
- <js-module name="ExtraInfo" src="www/ExtraInfo.js">
- <clobbers target="cordova.plugins.ExtraInfo"/>
- </js-module>
- <platform name="android">
- <config-file parent="/*" target="res/xml/config.xml">
- <feature name="ExtraInfo">
- <param name="android-package" value="cn.net.wenzhixin.cordova.ExtraInfo"/>
- </feature>
- </config-file>
- <source-file src="src/android/ExtraInfo.java" target-dir="src/cn/net/wenzhixin/cordova"/>
- <config-file target="AndroidManifest.xml">
- <uses-permission android:name="android.permission.READ_PHONE_STATE" />
- </config-file>
- </platform>
- </plugin>
复制代码 www下的JS代码:
- var exec = require('cordova/exec');
- var ExtraInfo = function(){
- };
- ExtraInfo.getExtra = function(success, error) {
- exec(success, error, "ExtraInfo", "getExtra", []);
- };
- if(!window.plugins){
- window.plugins = {};
- }
- if(!window.plugins.ExtraInfo){
- window.plugins.ExtraInfo = new ExtraInfo();
- }
- module.exports = new ExtraInfo();
复制代码
调用代码:
- define(function(require) {
- // var $ = require("jquery");
- // var justep = require("$UI/system/lib/justep");
- require("$UI/system/lib/cordova/cordova");
- //require("cordova!cn.net.wenzhixin.cordova");
-
- var Model = function() {
- this.callParent();
-
- };
- Model.prototype.button2Click = function(event){
- document.addEventListener('deviceready', function() {
- // var ExtraInfo = window.plugins.ExtraInfo;
- var ExtraInfo = require('cn.net.wenzhixin.cordova.ExtraInfo');
-
- ExtraInfo.getExtra(function(message) {
- alert(message);
- }, function(message) {
- alert(message);
- });
- });
- };
- return Model;
- });
复制代码
|
|