Simulating Keyboard Events in Android

前端 未结 2 639
闹比i
闹比i 2021-01-27 18:50

I have a project and I am trying to fire Keyboard events. I am using the Instrumentation Class, and it is working perfectly on the emulator, but when I launch it on my device, t

2条回答
  •  忘了有多久
    2021-01-27 19:21

    Actually, there is an easier method, that I found Using Activity class or WebView class. Both have the same function. The code looks something like this:

    webView.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_1));
    

提交回复
热议问题