Xamarin forms how to tell if an Android device is set to not allow rotation

WillAutioItrax 201 Reputation points
2021-02-08T20:59:52.507+00:00

I am implementing a Camera2 feature in our Xamarin Forms app. I'd like to know how to tell if the user has set their device to not allow rotations.
I can tell if it has been rotated. I'd like to know what the native setting is. Does it allow rotations. (I have read that Android allows us developers to over ride the native settings)
Thanks!

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,366 questions
0 comments No comments
{count} votes

Accepted answer
  1. Joe Manke 1,091 Reputation points
    2021-02-09T15:00:32.667+00:00

    You can check the system setting from your MainActivity with this code:

    bool rotationEnabled = Android.Provider.Settings.System.GetInt(ContentResolver, Android.Provider.Settings.System.AccelerometerRotation, 0) == 1;
    

    Source: https://stackoverflow.com/questions/20902775/how-to-check-if-auto-rotate-screen-setting-is-on-off-in-android-4-0

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Cole Xia (Shanghai Wicresoft Co,.Ltd.) 6,751 Reputation points
    2021-02-09T08:52:51.687+00:00

    Hello,

    Welcome to Microsoft Q&A!

    You can check if the device supports accelerometer .

       bool hasAccelerometer = PackageManager.HasSystemFeature(PackageManager.FeatureSensorAccelerometer);  
    

    Refer to https://stackoverflow.com/a/43093143/8187800 .


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.