1

I want to set Portrait Orientation and lock for ldpi and mdpi screens. and want to set Landscape orientation and lock for hdpi and xhdpi.

When app opened in 10 inch tablets it should be landscape it cant be portrait. like that when the app opened in android mobile it should be in portrait not landscape.

So please help me to fix this issue.

Please Refer this Question, its works for me :)

How to check an Android device is HDPI screen or MDPI screen?

        switch (getResources().getDisplayMetrics().densityDpi) {
        case DisplayMetrics.DENSITY_LOW:
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            break;
        case DisplayMetrics.DENSITY_MEDIUM:
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            break;
        case DisplayMetrics.DENSITY_HIGH:
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            break;
        case DisplayMetrics.DENSITY_XHIGH:
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            break;
        }
Community
  • 1
  • 1
rkaartikeyan
  • 1,977
  • 9
  • 29
  • 57
  • Here What is your issue?? – Subramanian Ramsundaram Dec 02 '13 at 14:38
  • @Homosapiens he stated his issue clearly – Gopal Gopi Dec 02 '13 at 14:39
  • @GopalRao he just want to do that but it seems no research/effort. – Subramanian Ramsundaram Dec 02 '13 at 14:41
  • @Homosapiens what kind of research i have to do? many documents and blogs are telling we can lock orientation for a app, Example if we set orientation in android manifest file it would applicable for all devices, if i set Portrait orientation for all devices its portrait. but i want in low size screens it should be portrait and high size screens it should be landscape. how i have to research for this? if you tell i will do for sure. – rkaartikeyan Dec 02 '13 at 14:46
  • @Homosapiens also there are millions of question already raised in stack-overflow and almost most of them are answered well. if there is no question similar to what i want then only we are asking by raise new Question. We are not blindly come and post questions. please try to understood bro. – rkaartikeyan Dec 02 '13 at 14:48
  • @rkaartikeyan cool bro. Really i did not mean that. Any how you can do this by write a code in your Activity. Do it in run time. – Subramanian Ramsundaram Dec 02 '13 at 14:55

1 Answers1

3

First see here to find whether device is hdpi or mdpi or xhdpi etc etc.

based on that lock your screen orientation.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (ldpi || mdpi) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    } else if(hdpi || xhdpi) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
}
Community
  • 1
  • 1
Gopal Gopi
  • 11,101
  • 1
  • 30
  • 43
  • Thanks This works for me http://stackoverflow.com/questions/5099550/how-to-check-an-android-device-is-hdpi-screen-or-mdpi-screen – rkaartikeyan Dec 02 '13 at 16:24