EDIT: Leaving the below for reference, but this clearly does NOT actually work. :(
He wants the application to be locked to portrait on cellphones, and be free to rotate on tablets.
Ugh. Well, you actually can accomplish this through the manifest. How you do it depends on what you want to define as a "tablet". Let's assume the cutoff is the Google-suggested sw600dp
(smallest width of 600dp is a good breakpoint for a 7" tablet).
You can make the following file structure in your res
folder:
res
- values
- styles.xml
- values-sw600dp
- styles.xml
In your values/styles.xml
(this will be your non-tablet style), define the following styles for your Activity
:
<!-- This will be a base style that will affect both tablet and non-tablet -->
<style name="BaseTheme" parent="{{pick a base theme here -- e.g. Theme.Light}}"/>
<!-- This is the local style that will be used on devices whose smallest width
is less than 600dp -->
<style name="BaseTheme.Activity">
<item name="android:screenOrientation">portrait</item>
</style>
In your values-sw600dp/styles.xml
:
<!-- This is the local style that will be used on devices whose smallest
width is greater than or equal to 600dp. We define nothing here other
than the fact that the style exists, so it will have the default screen
orientation - that is, it will rotate freely. -->
<style name="BaseTheme.Activity"/>
Now, in your AndroidManifest.xml
, inside your activity
tag, add:
android:theme="@style/BaseTheme.Activity"
And you should have the desired result. However, you should first remove all of the Java code you added to try to manage this yourself, as it will likely conflict with this causing unexpected results.