Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How do you emulate a keyboard flip?

While debugging my app using Monkey (which is almost as fun as the real thing), I managed to crash! Yay, that's what it's for, right?

Looking at the log (and while watching) I noticed that Monkey is occasionally doing:

:Sending Flip keyboardOpen=true

which seems to be part of my problem. When this happens, the screen in the emulator rotates 90 degrees, but this is NOT the same as a regular rotation you get by hitting KEYPAD_7. Here's a picture:

unusual screen orientation

It looks to me the emulator is emulating a keyboard opening (flip), which is subtly different from a rotation.

So the question is: How do I emulate that myself? Sure, running Monkey is neat, but waiting for it to randomly choose to send a keyboardOpen message is no way to debug a program.

like image 931
SMBiggs Avatar asked Nov 04 '22 12:11

SMBiggs


1 Answers

Maybe use the --pct-majornav to restrict the monkey to just the 'major' nav events (I'm assuming keyboard changes are 'major', I'm not sure though).

You could also look into writing a specific test based on the different but similar monkeyrunner framework: http://developer.android.com/guide/developing/tools/monkeyrunner_concepts.html ... but I don't see any way to inject keyboard flip codes.

I found this relevant SO question: Simulating opening/closing the hardware keyboard in emulator but the "answer" there is confusing and seems insufficient.

Not really your question, but related to your root issue:

Did you forget to include 'keyboardHidden' in the 'android:configChanges' section of the manifest file? (Or did you include it, but you don't handle the config change callbacks?)

The keyboard hide/reveal will restart your activity. You can either declare that you handle that restart, or if you don't, the OS will stop and restart the app itself.

See http://developer.android.com/guide/topics/resources/runtime-changes.html

Update

I believe this is the source for the monkey application's keyboard flip event. It looks like injecting a keyboard flip event would be relatively straight-forward: Open /dev/input/input0 and write 16 magical bytes into it.

Also, the source seems to have an undocumented --pct-flip option for controlling keyboard flip rates: link

like image 127
P.T. Avatar answered Nov 07 '22 06:11

P.T.