Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to read the QR Code of Mobile phone through Code scanning Gun in android

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how to read the mobile phone QR code through the code scanning gun in android, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.

1. Introduce the auxiliary class of code scanning equipment

Public class ScanGunKeyEventHelper {private final static long MESSAGE_DELAY = 500; / / delay 500ms to determine whether the scan code is completed. Private StringBuffer mStringBufferResult; / / scan code content private boolean mCaps; / / case sensitive private final Handler mHandler; private final BluetoothAdapter mBluetoothAdapter; private final Runnable mScanningFishedRunnable; private OnScanSuccessListener mOnScanSuccessListener; private String mDeviceName; public ScanGunKeyEventHelper (OnScanSuccessListener onScanSuccessListener) {mOnScanSuccessListener = onScanSuccessListener; mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter (); mStringBufferResult = new StringBuffer () MHandler = new Handler (); mScanningFishedRunnable = new Runnable () {@ Override public void run () {performScanSuccess ();}};} / * returns the result of successful code scan * / private void performScanSuccess () {String barcode = mStringBufferResult.toString () If (mOnScanSuccessListener! = null) mOnScanSuccessListener.onScanSuccess (barcode); mStringBufferResult.setLength (0);} / * Scancode gun event resolution * @ param event * / public void analysisKeyEvent (KeyEvent event) {int keyCode = event.getKeyCode (); / / letter case judgment checkLetterStatus (event) If (event.getAction () = = KeyEvent.ACTION_DOWN) {char aChar = getInputCode (event);; if (aChar! = 0) {mStringBufferResult.append (aChar);} if (keyCode = = KeyEvent.KEYCODE_ENTER) {/ / if it is an enter key, return mHandler.removeCallbacks (mScanningFishedRunnable) directly MHandler.post (mScanningFishedRunnable);} else {/ / delay post. If there are other events in the 500ms, mHandler.removeCallbacks (mScanningFishedRunnable); mHandler.postDelayed (mScanningFishedRunnable, MESSAGE_DELAY);}} / / check the shift key private void checkLetterStatus (KeyEvent event) {int keyCode = event.getKeyCode () If (keyCode = = KeyEvent.KEYCODE_SHIFT_RIGHT | | keyCode = = KeyEvent.KEYCODE_SHIFT_LEFT) {if (event.getAction () = = KeyEvent.ACTION_DOWN) {/ / press the shift key to indicate uppercase mCaps = true;} else {/ / release the shift key, indicating lowercase mCaps = false } / / get scan content private char getInputCode (KeyEvent event) {int keyCode = event.getKeyCode (); char aChar; if (keyCode > = KeyEvent.KEYCODE_A & & keyCode = KeyEvent.KEYCODE_0 & & keyCode

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report