简体   繁体   中英

Bluetooth scanner causing activity to clear

I am using a bluetooth handheld scanner that's connected to an Android tablet. When loading my Android project in Android Studio, I'm able to scan a barcode and the text is inserted into the activity text view. After about 4-5 seconds, the scanner will go into some sort of sleep mode (or at least I believe this is what it's doing when it makes a single short beep). Once this happens, the entire activity is cleared.

What can I do to prevent this from happening without using an API to connect to the bluetooth device?

If it helps, I'm using this to intercept the input from the scanner:

textView1.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
        if (id == EditorInfo.IME_ACTION_DONE || id == EditorInfo.IME_NULL) {
            if(textView1.length() > 0 && textView1.getText().toString() != ""){
                ...
            }
            ...
        }
    ...
    }

Here are the Debug and Logcat portions:

DEBUG

D/TextView: SYANI: Clipboard API is calling: clearFilter()
D/TextView: SYANI: Clipboard API is calling: unregisterClipboardEventListener()
D/ViewRootImpl@4fb149e[ScanActivity]: mHardwareRenderer.destroy()#4
                                      dispatchDetachedFromWindow
D/InputTransport: Input channel destroyed: fd=76
D/TextView: setTypeface with style : 0
D/TextView: setTypeface with style : 0
D/TextView: setTypeface with style : 0
D/ScrollView: initGoToTop
D/TextView: setTypeface with style : 0
D/ViewRootImpl@c4da0e5[ScanActivity]: ThreadedRenderer.create() translucent=false
D/InputTransport: Input channel constructed: fd=76
D/ViewRootImpl@c4da0e5[ScanActivity]: setView = DecorView@a3177ba[ScanActivity] touchMode=false
V/InputMethodManager: Not IME target window, ignoring
D/ViewRootImpl@c4da0e5[ScanActivity]: dispatchAttachedToWindow
D/ViewRootImpl@c4da0e5[ScanActivity]: Relayout returned: oldFrame=[0,0][0,0] newFrame=[0,0][800,1280] result=0x6 surface={isValid=true -1336414208} surfaceGenerationChanged=true
D/ViewRootImpl@c4da0e5[ScanActivity]: mHardwareRenderer.initialize() mSurface={isValid=true -1336414208} hwInitialized=true
D/ScrollView:  onsize change changed 
E/ViewRootImpl: sendUserActionEvent() returned.
D/ViewRootImpl@c4da0e5[ScanActivity]: MSG_RESIZED_REPORT: frame=Rect(0, 0 - 800, 1280) ci=Rect(0, 32 - 0, 0) vi=Rect(0, 32 - 0, 0) or=1
                                      MSG_WINDOW_FOCUS_CHANGED 1
D/ViewRootImpl@c4da0e5[ScanActivity]: mHardwareRenderer.initializeIfNeeded()#2 mSurface={isValid=true -1336414208}
V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@da1d5e0 nm : com.abc.project ic=null
I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
D/InputTransport: Input channel constructed: fd=80
                  Input channel destroyed: fd=93


LOGCAT

09-12 13:24:14.121 13426-13426/com.abc.project D/TextView: SYANI: Clipboard API is calling: clearFilter()
09-12 13:24:14.122 13426-13426/com.abc.project D/TextView: SYANI: Clipboard API is calling: unregisterClipboardEventListener()
09-12 13:24:14.146 13426-13426/com.abc.project D/ViewRootImpl@4fb149e[ScanActivity]: mHardwareRenderer.destroy()#4
    dispatchDetachedFromWindow
09-12 13:24:14.154 13426-13426/com.abc.project D/InputTransport: Input channel destroyed: fd=76
09-12 13:24:14.222 13426-13426/com.abc.project D/TextView: setTypeface with style : 0
09-12 13:24:14.223 13426-13426/com.abc.project D/TextView: setTypeface with style : 0
09-12 13:24:14.242 13426-13426/com.abc.project D/TextView: setTypeface with style : 0
09-12 13:24:14.246 13426-13426/com.abc.project D/ScrollView: initGoToTop
09-12 13:24:14.250 13426-13426/com.abc.project D/TextView: setTypeface with style : 0
09-12 13:24:14.282 13426-13426/com.abc.project D/ViewRootImpl@c4da0e5[ScanActivity]: ThreadedRenderer.create() translucent=false
09-12 13:24:14.297 13426-13426/com.abc.project D/InputTransport: Input channel constructed: fd=76
09-12 13:24:14.298 13426-13426/com.abc.project D/ViewRootImpl@c4da0e5[ScanActivity]: setView = DecorView@a3177ba[ScanActivity] touchMode=false
09-12 13:24:14.305 13426-13426/com.abc.project V/InputMethodManager: Not IME target window, ignoring
09-12 13:24:14.308 13426-13426/com.abc.project D/ViewRootImpl@c4da0e5[ScanActivity]: dispatchAttachedToWindow
09-12 13:24:14.335 13426-13426/com.abc.project D/ViewRootImpl@c4da0e5[ScanActivity]: Relayout returned: oldFrame=[0,0][0,0] newFrame=[0,0][800,1280] result=0x6 surface={isValid=true -1336414208} surfaceGenerationChanged=true
09-12 13:24:14.336 13426-13426/com.abc.project D/ViewRootImpl@c4da0e5[ScanActivity]: mHardwareRenderer.initialize() mSurface={isValid=true -1336414208} hwInitialized=true
09-12 13:24:14.343 13426-13426/com.abc.project D/ScrollView:  onsize change changed 
09-12 13:24:14.346 13426-13426/com.abc.project E/ViewRootImpl: sendUserActionEvent() returned.
09-12 13:24:14.362 13426-13426/com.abc.project D/ViewRootImpl@c4da0e5[ScanActivity]: MSG_RESIZED_REPORT: frame=Rect(0, 0 - 800, 1280) ci=Rect(0, 32 - 0, 0) vi=Rect(0, 32 - 0, 0) or=1
    MSG_WINDOW_FOCUS_CHANGED 1
09-12 13:24:14.363 13426-13426/com.abc.project D/ViewRootImpl@c4da0e5[ScanActivity]: mHardwareRenderer.initializeIfNeeded()#2 mSurface={isValid=true -1336414208}
09-12 13:24:14.371 13426-13426/com.abc.project V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@da1d5e0 nm : com.abc.project ic=null
09-12 13:24:14.371 13426-13426/com.abc.project I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
09-12 13:24:14.372 13426-13426/com.abc.project D/InputTransport: Input channel constructed: fd=80
    Input channel destroyed: fd=93

尽管不是最佳答案,但我关闭了省电模式来解决此问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM