我正在尝试从我添加的cordova插件中调用一个javascript函数:
下面是我的代码:
添加pulgin后生成的js文件:
cordova.define("cordova-plugin-custom-camera-preview.PreviewCamera", function(require, exports, module) { var previewCamera = {
createEvent: function(successCallback, errorCallback) {
}
}
var previewCamera = {
createEvent: function(successCallback, errorCallback) {
cordova.exec(successCallback,errorCallback, "CustomCameraPreview", "action_preview_camera_pulgin", "" );
}
}
});这就是我试图在html中调用上述函数的方式:
<script type="text/javascript" src="../plugins/cordova-plugin-custom-camera-preview/PreviewCamera.js"></script>
function customCamera( ) {
PreviewCamera.previewCamera.createEvent(function()
{
alert("S");
}, function()
{
alert("F");
});
}问题: 09-18 14:16:49.516 14182-14182/com.rule14.bancmate I/ is : INFO:CONSOLE(318)“未捕获ReferenceError:未定义插件”,来源: file:///android_asset/www/pages/xxx.html (318)
编辑: cordova-plugin.js的一部分:
cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [
{
"file": "plugins/cordova-plugin-camera/www/CameraConstants.js",
"id": "cordova-plugin-camera.Camera",
"clobbers": [
"Camera"
]
},
{
"file": "plugins/cordova-plugin-camera/www/CameraPopoverOptions.js",
"id": "cordova-plugin-camera.CameraPopoverOptions",
"clobbers": [
"CameraPopoverOptions"
]
},
{
"file": "plugins/cordova-plugin-camera/www/Camera.js",
"id": "cordova-plugin-camera.camera",
"clobbers": [
"navigator.camera"
]
},
{
"file": "plugins/cordova-plugin-camera/www/CameraPopoverHandle.js",
"id": "cordova-plugin-camera.CameraPopoverHandle",
"clobbers": [
"CameraPopoverHandle"
]
},
{
"file": "plugins/cordova-plugin-whitelist/whitelist.js",
"id": "cordova-plugin-whitelist.whitelist",
"runs": true
},
{
"file": "plugins/cordova-plugin-custom-camera-preview/PreviewCamera.js",
"id": "cordova-plugin-custom-camera-preview.PreviewCamera",
"clobbers": [
"PreviewCamera"
]
}
];
module.exports.metadata =
// TOP OF METADATA
{
"cordova-plugin-camera": "1.2.0",
"cordova-plugin-whitelist": "1.0.0",
"cordova-plugin-custom-camera-preview": "1.0"
}
// BOTTOM OF METADATA
});发布于 2015-09-18 17:25:12
这里是这个文件中的cordova_plugins.js add you插件引用,并在你需要调用的地方调用这个文件。
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="cordova_plugins.js"></script>
cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [
{
"file": "plugins/com.paypal.cordova.mobilesdk/www/cdv-plugin-paypal-mobile-sdk.js",
"id": "com.paypal.cordova.mobilesdk.PayPalMobile",
"clobbers": [
"PayPalMobile"
]
},
{
"file": "plugins/cordova-plugin-whitelist/whitelist.js",
"id": "cordova-plugin-whitelist.whitelist",
"runs": true
},
{
"file": "plugins/com.phonegap.plugins.barcodescanner/www/barcodescanner.js",
"id": "com.phonegap.plugins.barcodescanner.BarcodeScanner",
"clobbers": [
"cordova.plugins.barcodeScanner"
]
},
{
"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.media-capture/www/CaptureAudioOptions.js",
"id": "org.apache.cordova.media-capture.CaptureAudioOptions",
"clobbers": [
"CaptureAudioOptions"
]
},
{
"file": "plugins/org.apache.cordova.media-capture/www/CaptureImageOptions.js",
"id": "org.apache.cordova.media-capture.CaptureImageOptions",
"clobbers": [
"CaptureImageOptions"
]
},
{
"file": "plugins/org.apache.cordova.media-capture/www/CaptureVideoOptions.js",
"id": "org.apache.cordova.media-capture.CaptureVideoOptions",
"clobbers": [
"CaptureVideoOptions"
]
},
{
"file": "plugins/org.apache.cordova.media-capture/www/CaptureError.js",
"id": "org.apache.cordova.media-capture.CaptureError",
"clobbers": [
"CaptureError"
]
},
{
"file": "plugins/org.apache.cordova.media-capture/www/MediaFileData.js",
"id": "org.apache.cordova.media-capture.MediaFileData",
"clobbers": [
"MediaFileData"
]
},
{
"file": "plugins/org.apache.cordova.media-capture/www/MediaFile.js",
"id": "org.apache.cordova.media-capture.MediaFile",
"clobbers": [
"MediaFile"
]
},
{
"file": "plugins/org.apache.cordova.media-capture/www/capture.js",
"id": "org.apache.cordova.media-capture.capture",
"clobbers": [
"navigator.device.capture"
]
},
{
"file": "plugins\SQLite-1.0.5\www\SQLitePlugin.js",
"id": "org.pgsqlite.SQLitePlugin",
"clobbers": [
"SQLitePlugin"
]
}
,
{
"file": "plugins\ionic-plugin-keyboard-master\www\keyboard.js",
"id": "ionic-plugin-keyboard",
"clobbers": [
"IonicKeyboard"
]
}
];
module.exports.metadata =
// TOP OF METADATA
{
"com.paypal.cordova.mobilesdk": "3.1.8",
"cordova-plugin-whitelist": "1.0.0",
"com.phonegap.plugins.barcodescanner": "2.0.1",
"org.apache.cordova.camera": "0.3.6",
"org.apache.cordova.media-capture": "0.3.6",
"org.pgsqlite.SQLitePlugin": "1.0.5",
"com.ionic.keyboard.IonicKeyboard": "1.0.5"
}
// BOTTOM OF METADATA
});有关js中的调用使用方法,请参阅此文档
function startScan() {
cordova.plugins.barcodeScanner.scan(
function (result) {
},
function (error) {
}
);
}这样调用你的函数
cordova.plugins.camerapreview.setOnPictureTakenHandler(function(result){
});https://stackoverflow.com/questions/32647764
复制相似问题