LDK
LDK

Reputation: 379

Check if android device rotation possible

I want to know if the android device supports device rotation. I thought any Android device supports the screen rotation but my Samsung Galaxy View doesn't support any rotation.

I only found this code:

if (android.provider.Settings.System.getInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0) == 1){
    Toast.makeText(getApplicationContext(), "Auto Rotate is ON", Toast.LENGTH_SHORT).show();

} else {
    Toast.makeText(getApplicationContext(), "Auto Rotate is OFF", Toast.LENGTH_SHORT).show();
}

But this only lets me know if the user set the Screen rotation off or on, I want to know if it is at all possible.

Please help me, best wishes

Leo

Upvotes: 2

Views: 953

Answers (4)

Awais
Awais

Reputation: 1217

Every device supports the rotation feature although but you can not check that either device supports the rotation or not. You can only check the sensor and the rotation mode that if device is on portrait or on landscape.

Upvotes: 0

fluffyBatman
fluffyBatman

Reputation: 6704

With the aid of Kishore Jethava's answer, here is what it should look like.

public static boolean isRotationPossible(Context context) {
    boolean hasAccelerometer = context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER);

    return (hasAccelerometer && android.provider.Settings.System.getInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0) == 1);
}

Upvotes: 0

Kishore Jethava
Kishore Jethava

Reputation: 6834

You can check availability of sensor. here is official docs

PackageManager manager = getPackageManager();
boolean hasAccelerometer = manager.hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER);

Role of Accelerometer

The accelerometer is a built-in electronic component that measures tilt and motion. It is also capable of detecting rotation and motion gestures such as swinging or shaking.

The most common use for it is to activate auto screen rotation on mobile devices when the user changes their orientation from portrait to landscape or vice-versa.

Upvotes: 4

BIW
BIW

Reputation: 1

Maybe try to simply lock the application screen in one position so you will skip the checkout step if you can rotate :)

Upvotes: 0

Related Questions