user2062024 user2062024 - 1 year ago 89
Android Question

Android - How to lock orientation for different device?

I am trying to lock the phone to portrait and tablet to landscape.
I usually use AndroidManifest.xml - android:screenOrientation="portrait"
But how can I set orientation to tablet / phone differently?

Answer Source

The best solution is to load one parameter from res folder from specific value. So if Your app is running on tablet, the screen density must be great or equals to 600dp.

In folder: res/values-sw600dp/ create xml with param:

    <bool name="isTablet">true</bool>

In folder res/values/ create xml with param

    <bool name="isTablet">false</bool>

After that You will be able check if app is running on tablet or phone by using this code:

boolean tabletSize = getResources().getBoolean(R.bool.isTablet);
if (tabletSize) {
} else {

Source from:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download