How to restrict device orientation to Portrait when an application running on Small/Mobile screens.

I have managed to address for Androind and IOS but stuck with UWP and Windows 8.1.

Android
private bool isTablet(Context context)
{
return (context.Resources.Configuration.ScreenLayout & Android.Content.Res.ScreenLayout.SizeMask) >= Android.Content.Res.ScreenLayout.SizeLarge;
}

if (!isTablet(Application.Context))
RequestedOrientation = ScreenOrientation.Portrait;

Appreciate if you could share your knowledge on this.

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    In Visual Studio
    In the Solution Explorer pallet
    Right-click your UWP project.
    Select properties
    Choose the 'Application' group from the left pane
    Click the 'Package Manifest' button on the right pane
    image

    Then select the orientations you want.
    image

  • AshaarAshaar USMember ✭✭

    @ClintStLaurent said:
    In Visual Studio
    In the Solution Explorer pallet
    Right-click your UWP project.
    Select properties
    Choose the 'Application' group from the left pane
    Click the 'Package Manifest' button on the right pane
    image

    Then select the orientations you want.
    image

    Thank you for your reply, I was aware that we can do this.

    But my concern is, this will restrict for all devices(irrespective of Mobile/Tablet) rather only for mobile.

    Please correct if I am wrong.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    You are right. I read this line

    UWP and Windows 8.1.

    but missed the part about wanting to only apply to certain phones.

    Are you familiar with Device.Idiom ?
    if (Device.Idiom == TargetIdiom.Tablet)

    and Device.Os
    if (Device.OS == TargetPlatform.WinPhone)

    If you nest these checks you can determine nearly any device family

                if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows)
                {
                    if (Device.Idiom == TargetIdiom.Phone)
                    {
                        //This is therefore a Windows phone
                    }
                }
    
Sign In or Register to comment.