cordova create C:\Kapsel_Projects\BarcodeScannerDemo com.mycompany.barcodescanner BarcodeScannerDemo
cd C:\Kapsel_Projects\BarcodeScannerDemo
cordova platform add android
or
cordova platform add windows
or
cordova create ~/Documents/Kapsel_Projects/BarcodeScannerDemo com.mycompany.barcodescanner BarcodeScannerDemo
cd ~/Documents/Kapsel_Projects/BarcodeScannerDemo
cordova platform add ios
cordova plugin add cordova-plugin-device
cordova plugin add cordova-plugin-dialogs
cordova plugin add kapsel-plugin-barcodescanner --searchpath %KAPSEL_HOME%/plugins
or
cordova plugin add kapsel-plugin-barcodescanner --searchpath $KAPSEL_HOME/plugins
or
cordova plugin add phonegap-plugin-barcodescanner
<menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/menu_share" android:title="@string/menu_share" android:icon="@android:drawable/ic_menu_share" android:orderInCategory="1" android:showAsAction="withText|ifRoom"/> <item android:id="@+id/menu_encode" android:title="@string/menu_encode_vcard" android:icon="@android:drawable/ic_menu_sort_alphabetically" android:orderInCategory="2" android:showAsAction="withText|ifRoom"/> </menu>
<html>
<head>
<title>Barcode Scanner Sample</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script>
document.addEventListener("deviceready", init, false);
function init() {
}
function scan() {
log("scanning");
cordova.plugins.barcodeScanner.scan(scanSuccessCallback, scanErrorCallback);
}
function scanSuccessCallback(result) {
log(result.text);
}
function scanErrorCallback(error) {
navigator.notification.alert("Scanning failed: " + JSON.stringify(error));
}
function encode() {
log("encoding");
var stringToEncode = "http://www.sap.com";
cordova.plugins.barcodeScanner.encode(cordova.plugins.barcodeScanner.Encode.TEXT_TYPE, stringToEncode, encodeSuccessCallback, encodeErrorCallback);
}
function encodeSuccessCallback(result) {
log(JSON.stringify(result));
}
function encodeErrorCallback(error) {
navigator.notification.alert("Encoding failed: " + JSON.stringify(error));
}
function log(line) {
var results = document.getElementById("scan_results");
results.innerHTML+= "<br>" + line;
}
</script>
</head>
<body>
<h1>Barcode Scanner Sample</h1>
<button onclick="scan()">Scan</button>
<button onclick="encode()">Encode</button>
<div id="scan_results"></div>
</body>
</html>
cordova run android
or
cordova run ios
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>Barcode Scanner App</title>
<script id="sap-ui-bootstrap" src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js" data-sap-ui-theme="sap_bluecrystal" data-sap-ui-libs="sap.m, sap.ui.commons, sap.ndc"></script>
<script type="text/javascript" src="cordova.js"></script>
<script>
var app1 = new sap.m.App("myApp", {
initialPage: "page1"
});
var page1 = new sap.m.Page("page1", {
title: "Barcode Scanner"
});
var buttonScan = new sap.ndc.BarcodeScannerButton({
text: "Scan"
});
var buttonEncode = new sap.m.Button({
text: "Encode"
});
var textOp = new sap.m.Text({
text: "N/A"
});
var textOpResult = new sap.m.Text({
text: "N/A"
});
var oLayout2 = new sap.ui.layout.VerticalLayout("Layout2", {
content: [
buttonScan,
buttonEncode,
textOp,
textOpResult
]
});
page1.addContent(oLayout2);
app1.addPage(page1);
app1.placeAt("content"); // place the App into the HTML document
document.addEventListener(
"deviceready",
function() {
log("Device Ready", "All plugins are now ready to be called");
},
false
);
function scanSuccessCallback(result) {
log("Scan Succeeded", result.mParameters.text);
}
function scanFailCallback(error) {
navigator.notification.alert("Scanning failed: " + JSON.stringify(error));
}
function encode() {
var stringToEncode = "http://www.sap.com";
log("encoding", stringToEncode);
if (device.platform == "Android") { //Not supported on iOS
cordova.plugins.barcodeScanner.encode(cordova.plugins.barcodeScanner.Encode.TEXT_TYPE, stringToEncode, encodeSuccessCallback, encodeErrorCallback);
}
else {
log("Encoding is not supported on iOS. See https://github.com/wildabeast/BarcodeScanner/issues/106");
}
}
function encodeSuccessCallback(result) {
log(result.text);
}
function encodeErrorCallback(error) {
navigator.notification.alert("Encoding failed: " + JSON.stringify(error));
}
function log(operation, result) {
textOp.setText(operation);
textOpResult.setText(result);
}
buttonScan.attachScanSuccess(scanSuccessCallback);
buttonScan.attachScanFail(scanFailCallback);
buttonEncode.attachPress(encode);
</script>
</head>
<body class="sapUiBody">
<div id="content"></div>
</body>
</html>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
26 | |
25 | |
21 | |
12 | |
9 | |
8 | |
8 | |
8 | |
8 | |
8 |