Question

a while back I converted my app to include landscape mode, from each activity having screenOrientation="portrait" to this:

        <activity
        android:name="bundle.android.views.MainActivity"
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:screenOrientation="fullSensor">

I also handle configuration changes just fine in onConfigurationChanged in each activity.

But in hindsight, I only want edge cases with pop out hardware keyboards to get landscape mode. How do I adjust my manifest and code?

do I keep a certain combination android:configChanges ? the onConfigurationChanged class? insight appreciated

Was it helpful?

Solution

One option is to tackle this problem programmatically. What you could do is detect if the user has a hardware keyboard attached, and if so force the orientation into landscape mode. Here are two ways to detect a hardware keyboard:

http://developer.android.com/reference/android/content/res/Configuration.html#keyboard

and

if (getResources().getConfiguration().hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {

}

Once you have detected that the user has a hard keyboard you can force landscape mode on the user with:

myActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top