Qt for Android Android SDK development method and sample project using Honeywell scanner

1. Import the SDK file DataCollection.jar into the project.

2. Add the following code to AndroidManifest.xml to get scan permission.

<uses-permission android:name="com.honeywell.decode.permission.DECODE" />

3. Add BarcodeListener and TriggerListener to the declaration of the Activity class (such as MainActivity) for scanning key trigger processing and barcode event processing.

[java]  view plain copy  
  1. publicclass MainActivity extends AppCompatActivity implements BarcodeReader.BarcodeListener, BarcodeReader.TriggerListener   

4. Define the AidcManager and BarcodeReader objects in the Activity class (such as MainActivity), and through the BarcodeReader object, you can set the scan properties and use the scan function.

[java]  view plain copy  
  1. AidcManager manager;  
  2. BarcodeReader barcodeReader;  
5. Add the following code to the onCreate function to create the scan object, set the scan properties, and complete the preparation for the scan function.

[java]  view plain copy  
  1. AidcManager.create(thisnew AidcManager.CreatedCallback() {  
  2.         @Override  
  3.         publicvoid onCreated(AidcManager aidcManager) {   
  4.             //Create AidcManager and BarcodeReader objects  
  5.             manager = aidcManager;  
  6.             barcodeReader = manager.createBarcodeReader();  
  7.   
  8.             / / Set the scan properties, open the scan function  
  9.             try {  
  10.                 barcodeReader.setProperty(BarcodeReader.PROPERTY_CODE_128_ENABLED, true);  
  11.                 barcodeReader.setProperty(BarcodeReader.PROPERTY_QR_CODE_ENABLED, false);  
  12.                 barcodeReader.setProperty(BarcodeReader.PROPERTY_TRIGGER_CONTROL_MODE, BarcodeReader.TRIGGER_CONTROL_MODE_CLIENT_CONTROL);  
  13.   
  14.                 barcodeReader.claim();   //Open the scan function  
  15.             } catch(Exception e){  
  16.                 Toast.makeText(MainActivity.this "Failed to modify property" , Toast.LENGTH_SHORT ).show();  
  17.             }  
  18.   
  19.             //Register Trigger listener and Barcode listener  
  20.             barcodeReader.addTriggerListener(MainActivity.this);  
  21.             barcodeReader.addBarcodeListener(MainActivity.this);  
  22.         }  
  23.     });  
6. Rewrite the onTriggerEvent function to realize the functions of pressing the scan key to turn on the fill light and scanning, and popping the scan key to turn off the fill light and scanning.

[java]  view plain copy  
  1. @Override  
  2.     publicvoid onTriggerEvent(TriggerStateChangeEvent triggerStateChangeEvent) {   
  3.         try {  
  4.             barcodeReader.light(triggerStateChangeEvent.getState()); //Switch fill light  
  5.             barcodeReader.aim(triggerStateChangeEvent.getState());//开关瞄准线  
  6.             barcodeReader.decode(triggerStateChangeEvent.getState());//开关解码功能  
  7.         } catch(Exception e){  
  8.             Toast.makeText(this"开关扫描功能失败", Toast.LENGTH_SHORT).show();  
  9.         }  
  10.     }  
7、重写onBarcodeEvent函数,实现条码数据的接收。

[java]  view plain  copy
  1. @Override  
  2.     public void onBarcodeEvent(BarcodeReadEvent barcodeReadEvent) {  
  3.         String barcodeData = barcodeReadEvent.getBarcodeData(); //获取扫描数据  
  4.     }  
8、重写onFailureEvent函数,实现扫描失败时的处理,也可以不加任何处理,但是必须要有这个函数,否则Build时会报错。

[java]  view plain  copy
  1. @Override  
  2.     publicvoid onFailureEvent(BarcodeFailureEvent barcodeFailureEvent) {   
  3.   
  4.     }  
9. Add barcodeReader.release() in the onPause function; close the scan, and add barcodeReader.claim() in the onResume function; resume the scan.

10. Add the following code to the onDestroy function to turn off all scanning functions.

[java]  view plain copy  
  1. barcodeReader.removeTriggerListener(this);  
  2. barcodeReader.removeBarcodeListener(this);  
  3. barcodeReader.close();  
  4. manager.close();  

The sample project network disk link is as follows:

Link:  https://pan.baidu.com/s/1o8JsVii  Password: yphq

Download Qt for Android Demo:

https://download.csdn.net/download/clinuxf/10346428

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325518220&siteId=291194637