Set different directions for mobile phones and tablets on Android

I want to do the following in my application:

>Portrait mode for mobile phones only > Portrait mode and landscape mode for tablets

I know I can easily change the orientation in the manifest file, but it affects the entire application

I also thought about creating separate activities to handle different versions, but I don't know how to use the application to detect the type of device

Who knows how to solve this problem?

resolvent:

You can use the following code to distinguish between normal / large screens and prevent direction changes accordingly

public static boolean isTablet(Context context) {
    return (context.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK)
            >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>