[英]Need to call js function from cordova plugin -android
I am trying to invoke just a javascript function from my added cordova plugin : 我试图从添加的cordova插件中仅调用javascript函数:
below is my code : 下面是我的代码:
Generated js file after adding pulgin : 添加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", "" );
}
}
});
This is how im trying to invoke above function in html : 这就是我试图在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");
});
}
Issue : 09-18 14:16:49.516 14182-14182/com.rule14.bancmate I/chromium﹕ [INFO:CONSOLE(318)] "Uncaught ReferenceError: plugin is not defined", source: file:///android_asset/www/pages/xxx.html (318) 问题:09-18 14:16:49.516 14182-14182 / com.rule14.bancmate I / chromium:[INFO:CONSOLE(318)]“未捕获的ReferenceError:未定义插件”,来源:file:/// android_asset / www / pages / xxx.html(318)
EDIT : a part of cordova-plugin.js : 编辑: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
});
Here is the cordova_plugins.js add you plugin reference in this file and also call this file where you need to call. 这是cordova_plugins.js在此文件中添加您的插件引用,并在需要调用的地方调用此文件。
<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
});
refer this for call use method in js 将此参考为js中的调用使用方法
function startScan() {
cordova.plugins.barcodeScanner.scan(
function (result) {
},
function (error) {
}
);
}
call you function like this way 这样打电话给你
cordova.plugins.camerapreview.setOnPictureTakenHandler(function(result){
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.