【发布时间】:2021-10-05 21:30:20
【问题描述】:
我正在构建一个 Android QR 扫描仪应用,我使用了一个由“Android Coding Time”YouTube 频道共享的代码。代码指定读取文本、wifi和url。
应用程序最终读取了 URL,但它无法识别文本或 Wifi。附上代码,有什么想法吗?
// 我什至抛出“Barcode.FORMAT_ALL_FORMATS”,希望它能起作用,但它没有!
private void scanbarcode(ImageProxy image) {
@SuppressLint("UnsafeOptInUsageError") Image image1 = image.getImage();
assert image1 != null;
InputImage inputImage = InputImage.fromMediaImage(image1, image.getImageInfo().getRotationDegrees());
BarcodeScannerOptions options =
new BarcodeScannerOptions.Builder()
.setBarcodeFormats(
Barcode.FORMAT_ALL_FORMATS,
Barcode.FORMAT_QR_CODE,
Barcode.FORMAT_AZTEC)
.build();
// 开关块
int valueType = barcode.getValueType();
switch (valueType) {
case Barcode.TYPE_WIFI:
String ssid = barcode.getWifi().getSsid();
String password = barcode.getWifi().getPassword();
int type = barcode.getWifi().getEncryptionType();
break;
case Barcode.TYPE_URL:
if (!bd.isAdded()) {
bd.show(fragmentManager, "");
}
bd.fetchurl(barcode.getUrl().getUrl());
String title = barcode.getUrl().getTitle();
String url = barcode.getUrl().getUrl();
break;
case Barcode.TYPE_TEXT:
byte[] codeText = barcode.getRawValue().getBytes(StandardCharsets.UTF_8);
break;
【问题讨论】: