自定义键盘 - 捕获条形码扫描结果

时间:2016-04-22 11:38:38

标签: android keyboard android-softkeyboard custom-keyboard

好的,所以情况如下: 我正在使用键盘(https://github.com/AnySoftKeyboard/AnySoftKeyboard)和条形码扫描仪(https://github.com/dm77/barcodescanner)。当我按下键盘上的特定按钮时,它会打开条形码扫描器,扫描完成后,它会返回上一个屏幕(假设是消息应用程序)并显示结果。 所有精细和花花公子,除了我不能在EditText中插入结果的事实,因为输入连接“getCurrentInputConnection()”不同于初始的(在启动条形码扫描器活动之前),因为它是另一个实例(发生这种情况是因为我启动了条形码扫描程序活动,并且在我返回初始屏幕后(显示键盘和EditText聚焦的消息应用程序)。 以下是从任何应用程序插入任何EditText的代码:

InputConnection inputConnection = getCurrentInputConnection();
inputConnection.setComposingText(scanResult, 1);

关于如何解决这个问题的任何想法?

1 个答案:

答案 0 :(得分:0)

So, I've managed to solve this (for anyone who faces this issue), the problem was, when I received the result (in the previous screen), I had to make it wait 1 second (with runnable and handler - postDelayed), and then do getCurrentInputConnection() and paste the result inside.