蓝牙扫描器导致活动清除

时间:2018-09-13 15:46:11

标签: java android

我正在使用连接到Android平板电脑的蓝牙手持式扫描仪。在Android Studio中加载Android项目时,我可以扫描条形码并将文本插入到活动文本视图中。大约4到5秒钟后,扫描仪将进入某种睡眠模式(或者至少我相信这是它发出一声​​短促的哔哔声后所做的事情)。一旦发生这种情况,将清除整个活动。

如何在不使用API​​连接到蓝牙设备的情况下防止这种情况发生?

如果有帮助,我正在使用它来拦截来自扫描仪的输入:

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() != ""){
                ...
            }
            ...
        }
    ...
    }

以下是Debug和Logcat部分:

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

1 个答案:

答案 0 :(得分:0)

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