1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| private final ActivityResultLauncher<ScanOptions> barcodeLauncher = registerForActivityResult(new ScanContract(), result -> { if(result.getContents() == null) { Toast.makeText(MainActivity.this, "取消扫描~", Toast.LENGTH_LONG).show(); } else { Toast.makeText(MainActivity.this, "扫描成功!", Toast.LENGTH_LONG).show(); String result = result.getContents(); } });
public void scanner(View view){ ScanOptions options = new ScanOptions(); options.setDesiredBarcodeFormats(ScanOptions.ONE_D_CODE_TYPES); options.setPrompt("扫描条码"); options.setCameraId(0); options.setBeepEnabled(false); barcodeLauncher.launch(options); }
|