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 scan module data by android

2025-04-06 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 android scan module data, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

The details are as follows

Android reads scan module data * * undertake read data in dispatchKeyEvent method * *

Take the read data in the dispatchKeyEvent method

Private StringBuilder mScanCodeBuilder = new StringBuilder (); @ Override public boolean dispatchKeyEvent (@ NonNull KeyEvent event) {LogUtil.d (TAG, "dispatchKeyEvent" + event.getAction () + "," + event.getKeyCode ()); checkLetterStatus (event); / / determine uppercase and lowercase letters if (event.getAction () = = KeyEvent.ACTION_DOWN) {mScanCodeBuilder.append (getInputCode (event)) If (event.getKeyCode () = = KeyEvent.KEYCODE_ENTER) {/ / if it is an enter key, return String scanResult = mScanCodeBuilder.toString (); mScanCodeBuilder.setLength (0); LogUtil.d (TAG, "dispatchKeyEvent," + scanResult); String scanResults = scanResult.replace ("", ") } else {/ / delay post, if there are other events in the 500ms mHandler.removeCallbacks (mScanningFishedRunnable); mHandler.postDelayed (mScanningFishedRunnable, 500);} return true;} return super.dispatchKeyEvent (event);}

Judge upper and lowercase letters

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 to indicate lowercase mCaps = false;}

Read character method

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