tags:

views:

647

answers:

2

Hey all!

Is there a way to simulate opening/closing the 'hardware' keyboard in the emulator? I have to test some changes that I capture using getResources().getConfiguration().keyboardHidden and this would help a fair lot :)

Thank you in advance!

+2  A: 

I had this question once(about simulating keyboard slide-out/in) and was expecting to find something in the Simulating Hardware events using Emulator console section of the Emulator's official documentation but unfortunately I couldn't. I thought it would have been a lot easier if sliding a keyboard in/ out and its emulation were just a hardware signal to be sent to the kernel.

I had to then resort to the indirect method of changing the device orientation by depressing the PageUp button on the Numpad. When you change the orientation of the device like this and print the value of expression (getResources().getConfiguration().hardKeyboardHidden == config.HARDKEYBOARDHIDDEN_YES) you get different values for portrait and landscape. So changing the emulator orientation is somehow related to making the hardkeyboard slide out(not hidden) and slide in(hidden).

See if that works in your case...

Samuh
The problem is that I am showing different views for different orientations but I also change the layout if the keyboard is opened. It's a bit annoying not being able to simulate this in the emulator.
LambergaR
Did you try changing the orientation by pressing the PgUp button? By combining Orientation change with appropriate checks of hardKeyboardHidden property you can check if all your logic/predicates are being reached/satisfied.
Samuh
+4  A: 

To add to Samuh's explanation (which I didn't know -- good to know that I can still simulate opening/closing the hardware keyboard by changing orientation), you can test the difference between landscape with no keyboard and landscape with keyboard open, by changing the hardware configuration of the emulator's AVD: The AVD can be configured to either have a hardware keyboard or not. If your emulator has no hardware keyboard, the soft keyboard appears as you would expect, and going to landscape mode should appear as it would in landscape mode on a phone with no keyboard.

To configure the emulator AVD to act as if it has no hardware keyboard, in the AVD & SDK Manager tool, click "New" to add a new AVD, select your desired SDK level and other options, and under the Hardware section, add a new property for "Keyboard support", and set it to "No". In the AVD emulator "Details" dialog, this will show up as "hw.keyboard = no". Note you can also modify an existing AVD to toggle its keyboard support, by editing the <avd path>/avd/<AVD device name>.avd/config.ini file, and changing the hw.keyboard entry to yes or not. On Mac and Linux, is generally ~/.android/. I don't know where that is on Windows.

Based on Samuh's answer, that means you can check the behavior of the phone being in landscape mode with keyboard open (emulator has a hardware keyboard configured), or in landscape mode with no keyboard (emulator is configured with no keyboard). Two minor frustrations with this are 1) you can't necessarily emulate how it will look in landscape mode on a device that has a hardware keyboard, but the keyboard is hidden (if I understand correctly), and 2) you would have to run two separate emulators or at least two AVDs booted separately, in order to test those two different cases.

Joe