【发布时间】:2015-08-05 17:25:14
【问题描述】:
我使用插件 com.phonegap.plugins.barcodescanner 创建应用扫描二维码
但我在扫描时无法打开设备中的 LED 灯
如何解决问题
感谢大家的帮助!
【问题讨论】:
标签: cordova cordova-plugins barcode-scanner flashlight
我使用插件 com.phonegap.plugins.barcodescanner 创建应用扫描二维码
但我在扫描时无法打开设备中的 LED 灯
如何解决问题
感谢大家的帮助!
【问题讨论】:
标签: cordova cordova-plugins barcode-scanner flashlight
我找到了解决办法。
扫描时,如果您希望 LED 灯亮起,只需增大音量即可。如果要关闭 LED 灯,请降低音量
【讨论】:
只需显示一个按钮即可打开手电筒或在 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)
}**
);
【讨论】:
使用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
}
}
【讨论】: