I wanted to show different views on Tablet and Phones but I am not able to switch mode for device. Requirement for Tablet is Landscape mode and for Phone is in Potrait mode. What changes should I do in AndroidManifest.xml
so that a single generated apk file meets my requirements ?
Asked
Active
Viewed 610 times
0

Kara
- 6,115
- 16
- 50
- 57

Abhijit Muke
- 1,194
- 3
- 16
- 41
2 Answers
0
see the below line for your answer
Determine if the device is a smartphone or tablet?
Find screen size dynamically and set screen mode landscape or portrait mode.
set programmatically landscape or portrait mode.
How to control landscape and portrait programmatically in android?
0
Use java code in your activity to do this
if(isTabletDevice)
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
else
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
isTabletDevice code
public static boolean isTabletDevice(Context activityContext) {
// Verifies if the Generalized Size of the device is XLARGE to be
// considered a Tablet
boolean xlarge = ((activityContext.getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK) ==
Configuration.SCREENLAYOUT_SIZE_XLARGE);
// If XLarge, checks if the Generalized Density is at least MDPI
// (160dpi)
if (xlarge) {
DisplayMetrics metrics = new DisplayMetrics();
Activity activity = (Activity) activityContext;
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
// MDPI=160, DEFAULT=160, DENSITY_HIGH=240, DENSITY_MEDIUM=160,
// DENSITY_TV=213, DENSITY_XHIGH=320
if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT
|| metrics.densityDpi == DisplayMetrics.DENSITY_HIGH
|| metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM
|| metrics.densityDpi == DisplayMetrics.DENSITY_TV
|| metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH) {
// Yes, this is a tablet!
return true;
}
}
// No, this is not a tablet!
return false;
}

Arun C
- 9,035
- 2
- 28
- 42