自定义键盘 - 捕获条码扫描结果
Custom Keyboard - capturing barcode scan results
好的,情况是这样的:
我正在使用键盘 (https://github.com/AnySoftKeyboard/AnySoftKeyboard) and a barcode scanner (https://github.com/dm77/barcodescanner)。当我按下键盘上的特定按钮时,它会打开条形码扫描器,扫描后,它 returns 到前一个屏幕(比如说消息传递应用程序)并显示结果。
一切都很好,但我无法将结果插入 EditText,因为输入连接 "getCurrentInputConnection()" 与初始连接不同(在启动条形码扫描器 activity 之前),因为这是另一个实例(发生这种情况是因为我启动了条形码扫描仪 activity 并且在我返回初始屏幕后(显示键盘并聚焦 EditText 的消息传递应用程序)。
这是从任何应用程序插入任何 EditText 的代码:
InputConnection inputConnection = getCurrentInputConnection();
inputConnection.setComposingText(scanResult, 1);
关于如何解决这个问题有什么想法吗?
所以,我设法解决了这个问题(对于遇到这个问题的任何人),问题是,当我收到结果时(在上一个屏幕中),我不得不让它等待 1 秒(使用 runnable和处理程序 - postDelayed),然后执行 getCurrentInputConnection() 并将结果粘贴到其中。
好的,情况是这样的: 我正在使用键盘 (https://github.com/AnySoftKeyboard/AnySoftKeyboard) and a barcode scanner (https://github.com/dm77/barcodescanner)。当我按下键盘上的特定按钮时,它会打开条形码扫描器,扫描后,它 returns 到前一个屏幕(比如说消息传递应用程序)并显示结果。 一切都很好,但我无法将结果插入 EditText,因为输入连接 "getCurrentInputConnection()" 与初始连接不同(在启动条形码扫描器 activity 之前),因为这是另一个实例(发生这种情况是因为我启动了条形码扫描仪 activity 并且在我返回初始屏幕后(显示键盘并聚焦 EditText 的消息传递应用程序)。 这是从任何应用程序插入任何 EditText 的代码:
InputConnection inputConnection = getCurrentInputConnection();
inputConnection.setComposingText(scanResult, 1);
关于如何解决这个问题有什么想法吗?
所以,我设法解决了这个问题(对于遇到这个问题的任何人),问题是,当我收到结果时(在上一个屏幕中),我不得不让它等待 1 秒(使用 runnable和处理程序 - postDelayed),然后执行 getCurrentInputConnection() 并将结果粘贴到其中。