SoFunction
Updated on 2025-03-03

How to implement the function of sdutio configuration Zxing for scanning codes

Github open source project (Zxing) demo

The fastest call to the Zxing method

1. Related third-party library

2. Call the basic code scan

3. Get the return value

The specific code is as follows:

//1. Default option start intentnew IntentIntegrator().initiateScan(); // `this` is the current Activity
//2. Obtain the result:@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
 IntentResult result = (requestCode, resultCode, data);
 if(result != null) {
  if(() == null) {
   (this, "Cancel Scan the QR code", Toast.LENGTH_LONG).show();
  } else {
   (this, "Scan the code result:" + (), Toast.LENGTH_LONG).show();
  }
 } else {
  (requestCode, resultCode, data);
 }
}


apply plugin: ''
android {
 compileSdkVersion 25
 buildToolsVersion "25.0.2"
 defaultConfig {
  applicationId ""
  minSdkVersion 15
  targetSdkVersion 25
  versionCode 1
  versionName "1.0"
  testInstrumentationRunner ""
 }
 buildTypes {
  release {
   minifyEnabled false
   proguardFiles getDefaultProguardFile(''), ''
  }
 }
}
dependencies {
 compile fileTree(dir: 'libs', include: ['*.jar'])
 androidTestCompile(':espresso-core:2.2.2', {
  exclude group: '', module: 'support-annotations'
 })
 compile ':appcompat-v7:25.2.0'
 compile ':constraint-layout:1.0.1'
 testCompile 'junit:junit:4.12'
 //Only this is added to the new project compile ':zxing-android-embedded:3.5.0'
 //The ones that need to be checked are: //1. Preparation of warehouse: jcenter() in repositories //:appcompat-v7: The version number must be greater than 23 or more //: The version needs to be greater than or equal to 23.0.2, and the old version may cause compilation errors //If all the above conditions are met, just add compile ':zxing-android-embedded:3.5.0'}

Translation of IntentIntegrator related method annotation

setCaptureActivity: Set the active class to use. It can be any activity, but should be handled with additional use here.

setPrompt: Set a prompt to display on the capture screen instead of using the default.

setOrientationLocked: By default, the direction is locked. Set to false does not lock.

setCameraId: Use the specified camera ID.

setBeepEnabled: Set to false to disable the beep of scanning.

setBarcodeImageEnabled: set to true so that the barcode image is saved in the result intent and its path is sent.

setDesiredBarcodeFormats: Set the required barcode format scan.

initiateScan: Start scanning all known barcode types with default cameras.

setTimeout: Start scanning all known barcode types with default cameras. And start timer timeout completed

createScanIntent: Create a scan intent with the specified option.

The above is the implementation method of sdutio configuration Zxing for scanning codes introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!