mirror of
https://github.com/zxing/zxing.git
synced 2025-01-12 19:57:27 -08:00
Issue 1079 return metadata like byte segments and more in Intent extras; add raw bytes to intent integrator code
git-svn-id: https://zxing.googlecode.com/svn/trunk@2053 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
8f005274c0
commit
6de693fa06
|
@ -291,9 +291,10 @@ public final class IntentIntegrator {
|
|||
if (resultCode == Activity.RESULT_OK) {
|
||||
String contents = intent.getStringExtra("SCAN_RESULT");
|
||||
String formatName = intent.getStringExtra("SCAN_RESULT_FORMAT");
|
||||
return new IntentResult(contents, formatName);
|
||||
byte[] rawBytes = intent.getByteArrayExtra("SCAN_RESULT_BYTES");
|
||||
return new IntentResult(contents, formatName, rawBytes);
|
||||
}
|
||||
return new IntentResult(null, null);
|
||||
return new IntentResult();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -25,10 +25,16 @@ public final class IntentResult {
|
|||
|
||||
private final String contents;
|
||||
private final String formatName;
|
||||
private final byte[] rawBytes;
|
||||
|
||||
IntentResult(String contents, String formatName) {
|
||||
IntentResult() {
|
||||
this(null, null, null);
|
||||
}
|
||||
|
||||
IntentResult(String contents, String formatName, byte[] rawBytes) {
|
||||
this.contents = contents;
|
||||
this.formatName = formatName;
|
||||
this.rawBytes = rawBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,4 +51,11 @@ public final class IntentResult {
|
|||
return formatName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return raw bytes of the barcode content, if applicable, or null otherwise
|
||||
*/
|
||||
public byte[] getRawBytes() {
|
||||
return rawBytes;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -68,6 +68,7 @@ import java.text.DateFormat;
|
|||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -569,6 +570,25 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
|
|||
if (rawBytes != null && rawBytes.length > 0) {
|
||||
intent.putExtra(Intents.Scan.RESULT_BYTES, rawBytes);
|
||||
}
|
||||
Map<ResultMetadataType,?> metadata = rawResult.getResultMetadata();
|
||||
if (metadata != null) {
|
||||
Integer orientation = (Integer) metadata.get(ResultMetadataType.ORIENTATION);
|
||||
if (orientation != null) {
|
||||
intent.putExtra(Intents.Scan.RESULT_ORIENTATION, orientation);
|
||||
}
|
||||
String ecLevel = (String) metadata.get(ResultMetadataType.ERROR_CORRECTION_LEVEL);
|
||||
if (ecLevel != null) {
|
||||
intent.putExtra(Intents.Scan.RESULT_ERROR_CORRECTION_LEVEL, ecLevel);
|
||||
}
|
||||
List<byte[]> byteSegments = (List<byte[]>) metadata.get(ResultMetadataType.BYTE_SEGMENTS);
|
||||
if (byteSegments != null) {
|
||||
int i = 0;
|
||||
for (byte[] byteSegment : byteSegments) {
|
||||
intent.putExtra(Intents.Scan.RESULT_BYTE_SEGMENTS_PREFIX + i, byteSegment);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
Message message = Message.obtain(handler, R.id.return_scan_result);
|
||||
message.obj = intent;
|
||||
handler.sendMessageDelayed(message, INTENT_RESULT_DURATION);
|
||||
|
|
|
@ -110,6 +110,25 @@ public final class Intents {
|
|||
*/
|
||||
public static final String RESULT_BYTES = "SCAN_RESULT_BYTES";
|
||||
|
||||
/**
|
||||
* Key for the value of {@link com.google.zxing.ResultMetadataType#ORIENTATION}, if available.
|
||||
* Call intent.getIntExtra(RESULT_ORIENTATION).
|
||||
*/
|
||||
public static final String RESULT_ORIENTATION = "SCAN_RESULT_ORIENTATION";
|
||||
|
||||
/**
|
||||
* Key for the value of {@link com.google.zxing.ResultMetadataType#ERROR_CORRECTION_LEVEL}, if available.
|
||||
* Call intent.getStringExtra(RESULT_ERROR_CORRECTION_LEVEL).
|
||||
*/
|
||||
public static final String RESULT_ERROR_CORRECTION_LEVEL = "SCAN_RESULT_ERROR_CORRECTION_LEVEL";
|
||||
|
||||
/**
|
||||
* Prefix for keys that map to the values of {@link com.google.zxing.ResultMetadataType#BYTE_SEGMENTS},
|
||||
* if available. The actual values will be set under a series of keys formed by adding 0, 1, 2, ...
|
||||
* to this prefix. So the first byte segment is under key "SCAN_RESULT_BYTE_SEGMENTS_0" for example.
|
||||
*/
|
||||
public static final String RESULT_BYTE_SEGMENTS_PREFIX = "SCAN_RESULT_BYTE_SEGMENTS_";
|
||||
|
||||
/**
|
||||
* Setting this to false will not save scanned codes in the history.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue