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.
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.
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.
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.
7、重写onBarcodeEvent函数,实现条码数据的接收。
8、重写onFailureEvent函数,实现扫描失败时的处理,也可以不加任何处理,但是必须要有这个函数,否则Build时会报错。
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.
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.
- 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.
- AidcManager manager;
- BarcodeReader barcodeReader;
- AidcManager.create(this, new AidcManager.CreatedCallback() {
- @Override
- publicvoid onCreated(AidcManager aidcManager) {
- //Create AidcManager and BarcodeReader objects
- manager = aidcManager;
- barcodeReader = manager.createBarcodeReader();
- / / Set the scan properties, open the scan function
- try {
- barcodeReader.setProperty(BarcodeReader.PROPERTY_CODE_128_ENABLED, true);
- barcodeReader.setProperty(BarcodeReader.PROPERTY_QR_CODE_ENABLED, false);
- barcodeReader.setProperty(BarcodeReader.PROPERTY_TRIGGER_CONTROL_MODE, BarcodeReader.TRIGGER_CONTROL_MODE_CLIENT_CONTROL);
- barcodeReader.claim(); //Open the scan function
- } catch(Exception e){
- Toast.makeText(MainActivity.this , "Failed to modify property" , Toast.LENGTH_SHORT ).show();
- }
- //Register Trigger listener and Barcode listener
- barcodeReader.addTriggerListener(MainActivity.this);
- barcodeReader.addBarcodeListener(MainActivity.this);
- }
- });
- @Override
- publicvoid onTriggerEvent(TriggerStateChangeEvent triggerStateChangeEvent) {
- try {
- barcodeReader.light(triggerStateChangeEvent.getState()); //Switch fill light
- barcodeReader.aim(triggerStateChangeEvent.getState());//开关瞄准线
- barcodeReader.decode(triggerStateChangeEvent.getState());//开关解码功能
- } catch(Exception e){
- Toast.makeText(this, "开关扫描功能失败", Toast.LENGTH_SHORT).show();
- }
- }
- @Override
- public void onBarcodeEvent(BarcodeReadEvent barcodeReadEvent) {
- String barcodeData = barcodeReadEvent.getBarcodeData(); //获取扫描数据
- }
- @Override
- publicvoid onFailureEvent(BarcodeFailureEvent barcodeFailureEvent) {
- }
10. Add the following code to the onDestroy function to turn off all scanning functions.
- barcodeReader.removeTriggerListener(this);
- barcodeReader.removeBarcodeListener(this);
- barcodeReader.close();
- 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: