문제

I need some help with implementing the barcode reader plugin into my phonegap application.

I've already added the plugin via cli to my phonegap project. Now there is a plugin folder with the barcodescanner.js inside. I've added "'<'gap:plugin name="com.phonegap.plugins.barcodescanner" />" to my config.xml. And this is my index.html code :

<html>

<head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <script src="plugins/com.phonegap.plugins.barcodescanner/www/barcodescanner.js"></script>
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <title>Hello World</title>
    <script>
        function scanner() {
            cordova.plugins.barcodeScanner.scan(
                function(result) {
                    alert("We got a barcode\n" +
                        "Result: " + result.text + "\n" +
                        "Format: " + result.format + "\n" +
                        "Cancelled: " + result.cancelled);
                },
                function(error) {
                    alert("Scanning failed: " + error);
                }
            );
        }
    </script>
</head>

<body>
    <input type="button" value="Scan" onClick="scanner()" />
</body>

</html>

If I click on my button the Logcat says, that it cant find cordova.plugins...... Does anyone encountered that issue before?

도움이 되었습니까?

해결책

I don't see reference to cordova.js in your source and it's the only cordova-specific file you need to add. Using Cordova 3 CLI the plugins are imported automagically by scripts in cordova.js (no need to add reference to plugin's JS file).

Edit.: BTW don't copy the cordova.js file to your app folders, just use <script src="cordova.js"></script> in your html. The file specific to given platform will be placed in the platform's www folder during cordova prepare.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top