1
votes

I am trying to invoke just a javascript function from my added cordova plugin :

below is my code :

Generated js file after adding pulgin :

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 i m trying to invoke above function in 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)

EDIT : a part of 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
});
1
did u define your plugin in Cordova-plugin.js?Sameer Donga
@SameerDonga it is mentioned in doc that cordova.js automatically loads it inKOTIOS
I am talking about Cordova-plugin.jsSameer Donga
dont know more on this , i just refered tut and did that, can u plz guide more ..@SameerDongaKOTIOS
@SameerDonga i didnt added in cordova-plugin.js it auto upadted , plz see my editted question , what more i had missed ? is the invoking in html correct? it seems something wrong to me.KOTIOS

1 Answers

0
votes

Here is the cordova_plugins.js add you plugin reference in this file and also call this file where you need to call.

<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

function startScan() {

          cordova.plugins.barcodeScanner.scan(
              function (result) {                 
              },
              function (error) {                 
              }
          );
      }

call you function like this way

cordova.plugins.camerapreview.setOnPictureTakenHandler(function(result){
});