Essentials: [Enhancement] Try LinearAcceleration Sensor if Accelerometer doesn't exist.

Created on 4 Mar 2020  Â·  4Comments  Â·  Source: xamarin/Essentials

Bug report best practices: Submitting Issues

Description

The Accelerometer sensor runs on Android7.0(RedMi Note 4X) OK.
However, when it runs on Android8.1(Smartisan Pro2s), it gets error :specified method is not supported. I truely know my phone has accelerometer sensor, but the code doesn't work on Android8.1.

Steps to Reproduce

Accelerometer.Start(SensorSpeed.Normal)

Expected Behavior

Nomally start accelerometer sensor

Actual Behavior

Get error: specified method is not supported

Basic Information

Visual Studio 2019 16.4.5

  • Version with issue: Android8.1
  • Last known good version: Android7.0
  • IDE:
  • Platform Target Frameworks:

    • iOS: N/A

    • Android: Android 9.0

    • UWP: N/A

  • Android Support Library Version:
  • Nuget Packages: NuGet Package Manager - 5.4.0
  • Affected Devices: RedMi Note 4X / Smartisan Pro2s

Screenshots

Reproduction Link

enhancement ready-to-implement

Most helpful comment

Hi, James!
Thank you for receive your mail~
I meant that my device truely have an accelerometer sensor but I can't trigger that sensor before I sent you the issue.
However, there is a surprise!!! When I try thousands of ways such as use Android.Hardware to instead of Xamarin,( although I can't use Android.Hardware properly at that time) . When I failed again and prepare to go to bed, I tried Xamarin again, you can't believe that sensor began to work!!!
Yes, now I can use Xamarin to trigger accelerometer, But I was trying to return the issue situation such as power low or FlightMode, however, it can‘t’ go back to that issue situation. So I don't know WHAT ACTION I DID make the sensor began working...
Now I am happy to see sensor working, but a little depressing in I can't find the root cause of the issue.
Could you find some cause from these cue I said? And now I prepare to find more android phone to test to find the cause and then feedback you.
Last, I am very appreciate what you said "but it is android so who knows" :) haha

All 4 comments

And how can I use LinearAcceleration sensor?

I can only find Accelerometor...

We use a check for the Accelerometer. If it is returning null then it means there isn't a sensor. It could be that these devices don't supply an Accelerometer on them.

Platform.SensorManager?.GetDefaultSensor(SensorType.Accelerometer) != null;

The difference being that Linear Acceleration sensor excludes gravity. We could do a feature improvement that checks to see if the Accelerometer doesn't exist then try to use linear acceleration sensor.

I find it strange that the devices dont' report back an accelerometer, but it is android so who knows :)

Hi, James!
Thank you for receive your mail~
I meant that my device truely have an accelerometer sensor but I can't trigger that sensor before I sent you the issue.
However, there is a surprise!!! When I try thousands of ways such as use Android.Hardware to instead of Xamarin,( although I can't use Android.Hardware properly at that time) . When I failed again and prepare to go to bed, I tried Xamarin again, you can't believe that sensor began to work!!!
Yes, now I can use Xamarin to trigger accelerometer, But I was trying to return the issue situation such as power low or FlightMode, however, it can‘t’ go back to that issue situation. So I don't know WHAT ACTION I DID make the sensor began working...
Now I am happy to see sensor working, but a little depressing in I can't find the root cause of the issue.
Could you find some cause from these cue I said? And now I prepare to find more android phone to test to find the cause and then feedback you.
Last, I am very appreciate what you said "but it is android so who knows" :) haha

Thanks for the update and will close out. Yeah perhaps the sensor was just turned off for the time being :(

Was this page helpful?
0 / 5 - 0 ratings