Reputation: 4753
I'm wondering if there's a way to figure out what kind of a physical keyboard ("portrait", like e.g. Droid Pro or "landscape", like e.g. HTC Mytouch Slide) device has?
I would like to automatically switch the activity orientation when the physical keyboard is activated so that the EditText in the activity is parallel to the keyboard.
I've tried a rotation/orientation solution from here, but on my test phone with landscape sliding keyboard I had to reverse Landscape and Portrait to make it work properly, which makes me think that on some devices it'll have to be other way around.
Comparing screen width and height, like some other answers there suggest, also seems iffy. Is there any other method perhaps?
Upvotes: 1
Views: 227
Reputation: 4753
It looks like there's no need to know the keyboard type: for the purpose of setting the correct orientation of the activity it seems to be sufficient to set it to sensor orientation from the onConfigurationChanged handler (which in turn is called when the physical keyboard is opened or closed):
@Override
public void onConfigurationChanged(final Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}
Upvotes: 1