Reputation: 2195
Is there a way for the Android Manifest to be different depending on screen size? I want android:configChanges to not include "orientation" if the device is a tablet (ie xlarge screen size)
Moreover, I want android:screenOrientation to be different depending on which device is used. Any advice?
Upvotes: 0
Views: 654
Reputation: 1287
please have a look at this ......... supports-screens android:resizeable=["true"| "false"] android:smallScreens=["true" | "false"] android:normalScreens=["true" | "false"] android:largeScreens=["true" | "false"] android:xlargeScreens=["true" | "false"] android:anyDensity=["true" | "false"] android:requiresSmallestWidthDp="integer" android:compatibleWidthLimitDp="integer" android:largestWidthLimitDp="integer ............... It will be Handle your screen
Upvotes: 0
Reputation: 8317
I know of no way to do something that complex in AndroidManifest.xml, however you can do it programmatically via Activity.setRequestedOrientation()
method. It's easy enough to wrap this in a utility class and then query your environment accordingly. One word of warning though - if calling this method does actually result in an orientation change, your Activity's onCreate()
will be called a second time. Another thing that might come in handy if you choose to go this route, if the following evaluates to true:
if((cfg.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {...}
Then you are on a tablet device, or at least your layouts are being loaded from layout-large (if you have one). Puting it all together, the following would lock a tablet into landscape mode and phones into portrait mode:
if ((cfg.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
return true;
} else if ((cfg.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) {
return false;
} else if ((cfg.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) {
return false;
} else {
// Assume that all other ratings are tablets or possibly even larger devices; there is an
// extra large spec however it is only available OS versions 3.x and above so there is no clean way to query for this state.
return true;
}
Upvotes: 1