Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: CompassError code 3 on Android 10 #63

Open
3 tasks done
pdrhlik opened this issue Apr 12, 2021 · 8 comments
Open
3 tasks done

Documentation: CompassError code 3 on Android 10 #63

pdrhlik opened this issue Apr 12, 2021 · 8 comments

Comments

@pdrhlik
Copy link

pdrhlik commented Apr 12, 2021

Bug Report

Problem

When subscribing to a watchHeading function, I get a CompassError {code: 3} response. It works on older Android phones. I haven't tested iOS. If I browsed the code correctly. The error code is neither one of CompassError.COMPASS_INTERNAL_ERR CompassError.COMPASS_NOT_SUPPORTED.

What is expected to happen?

It should work.

What does actually happen?

I get an undocumented CompassError.

Information

It doesn't work on Android 10.

Command or Code

import { DeviceOrientation } from '@ionic-native/device-orientation/ngx';

constructor(
    private deviceOrientation: DeviceOrientation
  ) { }

this.compass = this.deviceOrientation.watchHeading({frequency: 500}).subscribe(data => {
       // logic
});

Environment, Platform, Device

I used Angular 11, Ionic framework 5 and Capacitor.

Version information

ionic info output:

Ionic:

   Ionic CLI                     : 6.13.1 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.6.4
   @angular-devkit/build-angular : 0.1102.8
   @angular-devkit/schematics    : 9.1.0
   @angular/cli                  : 11.2.8
   @ionic/angular-toolkit        : 2.3.3

Capacitor:

   Capacitor CLI   : 2.4.7
   @capacitor/core : 2.4.7

Cordova:

   Cordova CLI       : 9.0.0 ([email protected])
   Cordova Platforms : not available
   Cordova Plugins   : not available

Utility:

   cordova-res (update available: 0.15.3) : 0.15.2
   native-run (update available: 1.3.0)   : 1.2.2

System:

   Android SDK Tools : 26.1.1 (/Users/datigo/Library/Android/sdk)
   ios-deploy        : 1.10.0
   ios-sim           : ios-sim/9.0.0 darwin-x64 node-v12.18.3
   NodeJS            : v12.18.3 (/usr/local/Cellar/node@12/12.18.3/bin/node)
   npm               : 6.14.6
   OS                : macOS Catalina
   Xcode             : Xcode 12.4 Build version 12D4e

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
@breautek
Copy link

Error code 3 means the android device doesn't have a sensor available to use:

this.setStatus(CompassListener.ERROR_FAILED_TO_START);

Despite of the suppress deprecation, the method doesn't appear to be deprecated: https://developer.android.com/reference/android/hardware/SensorManager#getSensorList(int)

So this suggest that your device doesn't have an Orientation sensor. The constant is deprecated however, so perhaps you can try replacing it with SensorManager.getOrientation() instead?

@pdrhlik
Copy link
Author

pdrhlik commented Apr 13, 2021

Thanks a lot for the clarification @breautek. I didn't realise my phone doesn't have the sensor, which really is the case. So everything's ok then.

I would only suggest documenting ERROR_FAILED_TO_START on the main page so it's a bit more obvious for other people. Thanks again!

@pdrhlik pdrhlik closed this as completed Apr 13, 2021
@breautek
Copy link

We can leave this ticket as a reminder to improve documentation

@breautek breautek reopened this Apr 13, 2021
@breautek breautek changed the title CompassError code 3 on Android 10 Documentation: CompassError code 3 on Android 10 Apr 13, 2021
@valeckonext
Copy link

valeckonext commented Oct 4, 2022

I am experiencing the same issue using an "SM A125U1" phone (Android 12).

Would it be possible for the plugin to throw CompassError.COMPASS_NOT_SUPPORTED when this happens?

@loicparent
Copy link

Hello,

I am experiencing the same issue with a Xiaomi Redmi Note 11.

When I go to the Google Maps App, the compass indication works fine and smoothly. So I don't suppose this is about the sensor … maybe a permission or something else?

In my Ionic app, when I try to watch the headings, I get this error code 3.

Kind regards,
Loïc

@loicparent
Copy link

Hello,

No news about the previous message ⬆️ ?
I still have the issue (CompassError Code 3) on Xiaomi Redmi Note 10 and 11 even if the compass is well indicated in other apps.

Someone could help me with this?

Thanks,
Loïc

@breautek
Copy link

Hello,

No news about the previous message ⬆️ ? I still have the issue (CompassError Code 3) on Xiaomi Redmi Note 10 and 11 even if the compass is well indicated in other apps.

Someone could help me with this?

Thanks, Loïc

#63 (comment)

Error code 3 is returned if the compass sensor could not start, which is the case if the sensor could not be found. This is likely because the sensor (TYPE_ORIENTATION) is deprecated and has been deprecated for some time now and replaced with a non-sensor getOrientation API.

There is no open PR that makes this change, but there is #78 which attempts to simulate orientation sensor by fusing two different sensors together. I'm not sure if I agree with this approach, but you could test it to see if it solves your problem.

@loicparent
Copy link

Hello @breautek,

Thank you for your reply :)

I tried to replace the file compassListener.java in /node_modules/cordova-plugin-device-orientation/src/android/CompassListener.java.

I see a little difference because I don't get an error that don't return the event callback data BUT, now, the event is returned but with incomplete values:

{
  headingAccuracy: 3
  magneticHeading: undefined
  timestamp: 1693572512780
  trueHeading: undefined
}

Do you have an idea why?

Kind regards,
Loïc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants