我使用插件com.phonegap.plugins.barcodescanner创建应用程序扫描二维码
但扫描时我无法打开设备中的led灯
如何解决问题
谢谢大家的帮助!
我找到了解决方案。
扫描时,如果要让LED灯亮起,请增加音量。 如果要关闭LED,请减小音量
使用cordova-plugin-flashlight:
function scanlicht(enable) {
window.plugins.flashlight.available(function (isAvailable) {
if (isAvailable) {
if (enable) {
window.plugins.flashlight.switchOn(
function () { },
function () { },
{ intensity: 0.3}
);
} else {
window.plugins.flashlight.switchOff();
}
}
});
}
function scan(){
scanlicht(true);
cordova.plugins.barcodeScanner.scan(
function (result) {
scanlicht(false);
.... your code ....
}, function (error) {
scanlicht(false);
alert("Scanning failed: " + error);
},null
}
}
只需显示一个按钮即可打开割炬或打开Android割炬:
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);
},
**{
showTorchButton : true, // iOS and Android
torchOn: true, // Android, launch with the torch switched on (if available)
}**
);