android set app to portrait only, except when keyboard pulled out

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

Answers


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);

Need Your Help


About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.