|
| 1 | +--- |
| 2 | +layout: default-layout |
| 3 | +title: Receive Results - Dynamsoft Barcode Reader Android |
| 4 | +description: Learn how to receive captured results when using Dynamsoft Barcode Reader Android edition. |
| 5 | +keywords: Receive Results, Android |
| 6 | +needAutoGenerateSidebar: true |
| 7 | +needGenerateH3Content: true |
| 8 | +noTitleIndex: true |
| 9 | +--- |
| 10 | + |
| 11 | +# Receive Results |
| 12 | + |
| 13 | +## Receive Results from CapturedResultReceiver |
| 14 | + |
| 15 | +If you only need barcode results, use `onDecodedBarcodesReceived`. |
| 16 | + |
| 17 | +<div class="sample-code-prefix"></div> |
| 18 | +>- Java |
| 19 | +>- Kotlin |
| 20 | +> |
| 21 | +>1. |
| 22 | +```java |
| 23 | +mRouter.addResultReceiver(new CapturedResultReceiver() { |
| 24 | + @Override |
| 25 | + public void onDecodedBarcodesReceived(@NonNull DecodedBarcodesResult result) { |
| 26 | + // Add your code to use the DecodedBarcodesResult |
| 27 | + } |
| 28 | +}); |
| 29 | +``` |
| 30 | +2. |
| 31 | +```kotlin |
| 32 | +cvr.addResultReceiver(object: CapturedResultReceiver{ |
| 33 | + override fun onDecodedBarcodesReceived(result: DecodedBarcodesResult) { |
| 34 | + // Add your code to use the DecodedBarcodesResult |
| 35 | + } |
| 36 | +}) |
| 37 | +``` |
| 38 | + |
| 39 | +Likewise, in scenarios such as driver license parsing, you can get a `ParsedResult` directly from `onParsedResultsReceived`. |
| 40 | + |
| 41 | +<div class="sample-code-prefix"></div> |
| 42 | +>- Java |
| 43 | +>- Kotlin |
| 44 | +> |
| 45 | +>1. |
| 46 | +```java |
| 47 | +mRouter.addResultReceiver(new CapturedResultReceiver() { |
| 48 | + @Override |
| 49 | + public void onParsedResultsReceived(@NonNull ParsedResult result) { |
| 50 | + // Add your code to use the ParsedResult |
| 51 | + } |
| 52 | +}); |
| 53 | +``` |
| 54 | +2. |
| 55 | +```kotlin |
| 56 | +cvr.addResultReceiver(object: CapturedResultReceiver{ |
| 57 | + override fun onParsedResultsReceived(result: ParsedResult) { |
| 58 | + // Add your code to use the ParsedResult |
| 59 | + } |
| 60 | +}) |
| 61 | +``` |
| 62 | + |
| 63 | +If you need multiple result types at the same time, `onCapturedResultReceived` is more convenient. |
| 64 | + |
| 65 | +<div class="sample-code-prefix"></div> |
| 66 | +>- Java |
| 67 | +>- Kotlin |
| 68 | +> |
| 69 | +>1. |
| 70 | +```java |
| 71 | +mRouter.addResultReceiver(new CapturedResultReceiver() { |
| 72 | + @Override |
| 73 | + public void onCapturedResultReceived(@NonNull CapturedResult result) { |
| 74 | + // You can get both ParsedResult and DecodedBarcodesResult |
| 75 | + } |
| 76 | +}); |
| 77 | +``` |
| 78 | +2. |
| 79 | +```kotlin |
| 80 | +cvr.addResultReceiver(object: CapturedResultReceiver{ |
| 81 | + override fun onCapturedResultReceived(result: CapturedResult) { |
| 82 | + // You can get both ParsedResult and DecodedBarcodesResult |
| 83 | + val parsedResult = result.parsedResult |
| 84 | + val decodedBarcodesResult = result.decodedBarcodesResult |
| 85 | + } |
| 86 | +}) |
| 87 | +``` |
| 88 | + |
| 89 | +## Receive Results from Capture Methods |
| 90 | + |
| 91 | +The result is returned as a `CapturedResult` object when using `capture` methods. You can get the types you want from the `CapturedResult` object. |
| 92 | + |
| 93 | +<div class="sample-code-prefix"></div> |
| 94 | +>- Java |
| 95 | +>- Kotlin |
| 96 | +> |
| 97 | +>1. |
| 98 | +```java |
| 99 | +CapturedResult capturedResult = mRouter.capture("Your file path",EnumPresetTemplate.PT_READ_BARCODES_READ_RATE_FIRST); |
| 100 | +DecodedBarcodesResult decodedBarcodesResult = capturedResult.getDecodedBarcodesResult(); |
| 101 | +BarcodeResultItem[] barcodeResultItems = decodedBarcodesResult.getItems(); |
| 102 | +for(BarcodeResultItem barcodeResultItem: barcodeResultItems) |
| 103 | +{ |
| 104 | + String barcodeText = barcodeResultItem.getText(); |
| 105 | + String barcodeFormatString = barcodeResultItem.getFormatString(); |
| 106 | +} |
| 107 | +``` |
| 108 | +2. |
| 109 | +```kotlin |
| 110 | +val capturedResult = mRouter.capture("Your file path", EnumPresetTemplate.PT_READ_BARCODES_READ_RATE_FIRST) |
| 111 | +val decodedBarcodesResult = capturedResult.decodedBarcodesResult |
| 112 | +val barcodeResultItems = decodedBarcodesResult.items |
| 113 | +for (barcodeResultItem in barcodeResultItems) { |
| 114 | + val barcodeText = barcodeResultItem.text |
| 115 | + val barcodeFormatString = barcodeResultItem.formatString |
| 116 | +} |
| 117 | +``` |
| 118 | + |
| 119 | +## Receive Results from IntermediateResultReceiver |
| 120 | + |
| 121 | +To use `IntermediateResultReceiver`, you need to get the `IntermediateResultManager` from `CaptureVisionRouter` first. Then, you can add result receiver to the `IntermediateResultManager` for receiving intermediate results. |
| 122 | + |
| 123 | +<div class="sample-code-prefix"></div> |
| 124 | +>- Java |
| 125 | +>- Kotlin |
| 126 | +> |
| 127 | +>1. |
| 128 | +```java |
| 129 | +mRouter.getIntermediateResultManager().addResultReceiver(new IntermediateResultReceiver() { |
| 130 | + @Override |
| 131 | + public void onLocalizedBarcodesReceived(@NonNull LocalizedBarcodesUnit unit, IntermediateResultExtraInfo info) { |
| 132 | + if (unit.getCount() != 0) |
| 133 | + { |
| 134 | + for (LocalizedBarcodeElement element: unit.getLocalizedBarcodes()) |
| 135 | + { |
| 136 | + // LocalizedBarcodeElement is the basic element representing a localized barcode |
| 137 | + // Add your code to use the LocalizedBarcodeElement |
| 138 | + } |
| 139 | + } |
| 140 | + } |
| 141 | +}); |
| 142 | +``` |
| 143 | +2. |
| 144 | +```kotlin |
| 145 | +cvr.intermediateResultManager.addResultReceiver(object: IntermediateResultReceiver |
| 146 | +{ |
| 147 | + override fun onLocalizedBarcodesReceived( |
| 148 | + unit: LocalizedBarcodesUnit, |
| 149 | + info: IntermediateResultExtraInfo? |
| 150 | + ) { |
| 151 | + for (element: LocalizedBarcodeElement in unit.localizedBarcodes) |
| 152 | + { |
| 153 | + // LocalizedBarcodeElement is the basic element representing a localized barcode |
| 154 | + // Add your code to use the LocalizedBarcodeElement |
| 155 | + } |
| 156 | + } |
| 157 | +}) |
| 158 | +``` |
0 commit comments