apache / cordova-plugin-device-orientation

Apache Cordova Device Orientation Plugin
https://cordova.apache.org/
Apache License 2.0
58 stars 83 forks source link

Increasing reports of compass not working on some android devices #64

Open chrisgeorge0911 opened 3 years ago

chrisgeorge0911 commented 3 years ago

Bug Report

Problem

I've had an app released for a few years using this plugin to provide magnetic heading data in order to orient a compass. Increasingly in the last year I've had customers report that the compass isn't working on a selection of android phones, all of which have magnetometer sensors.

Devices are: Motorola Razr 5g Sony Xperia 5 ii Motorola G6

What does actually happen?

navigator.compass is returning false, implying that the compass sensor is not recognised.

Investigated switching to W3C orientation, but it does not give magnetic heading so is not fit for purpose. This plugin has been great for me.

Information

Using plugin v2.01 - Cordova 9.0

Checklist

alexbainbridge commented 3 years ago

What did you do in the end @chrisgeorge0911 ? We are using this plugin and struggling to get compass on android on devices are are sure have the right sensors.

I think we may end up using this plugin for iOS (as is native, so no permission request issues) and W3C or similar (like Capacitor Motion) for Android.

chrisgeorge0911 commented 3 years ago

I haven't done anything yet... the numbers reporting the issue are still fairly small (I have more iOS customers than android at the moment)... but I fear it's only going to get worse. The problem I've found with W3C is that it's not oriented around North, so no good for a compass (or at least I could not get this to work).

HarelM commented 3 years ago

I've just got my first report from an android device: Manufacture: OnePlus Model: HD1913 Platform: Android OS version: 11 I see an error in the log, but I get Error: [object Object], probably due to bad formatting of the error on my part. I can't use W3C due to iOS "localhost" issue and all other kind of bugs and quirks. If anyone finds the problem before I do please let me know, I'll see to what extent the user who's facing this issue will go.

chrisgeorge0911 commented 2 years ago

Another report of this Nokia 8.3 Android 11

mgurzixo commented 2 years ago

FYI, I did a fork and modified the plugin for using magnetometer and accelerometer. Now it works everywhere. It is available here.

I don´t know how to create a PR.

Enjoy!

HarelM commented 2 years ago

Opening a PR is very easy - all you need to do is click contribute --> open pull request: Write some notes on what you did and what it solves and click create or submit, I don't remember. but @mgurzixo how do you know that this solves this issue?

image
mgurzixo commented 2 years ago

@HarelM : I added an update explaining the patch. In fact, I rewrote src/android/CompassListener.java.

Thanks for the info about PRs. I will try to create one ;)

alexbainbridge commented 2 years ago

Thank you @mgurzixo for your work on this - just what we need so can remove some of our Android only hacks in our apps! I see you closed the PR - shouldn't it be left open for the maintainers to accept now you have submitted your updates?

breautek commented 2 years ago

I see you closed the PR - shouldn't it be left open for the maintainers to accept now you have submitted your updates

I've reopened the PR so that it doesn't get lost.

lahirudx commented 1 year ago

FYI, I did a fork and modified the plugin for using magnetometer and accelerometer. Now it works everywhere. It is available here.

I don´t know how to create a PR.

Enjoy!

Hi @mgurzixo, I just added your plugin to my project. But it's not working in Androids. Works for iOS.

Tested on Galaxy Note 22, 23.

Thanks.