Does the Gyroscope plugin work in the Android emulator?

Title says it all. I’m successfully injecting Gyroscope into my page component, and I’m subscribing to this.gyroscope.getCurrent() and this.gyroscope.watch() without errors – but the subscriptions never detect any events.

The emulator has a screen for adjusting the orientation of the virtual device, complete with a fancy 3D representation of the phone – so I would expect this to work.

My code:

import { Component } from '@angular/core';
import { Subscription } from 'rxjs/Subscription';

import { Gyroscope, GyroscopeOrientation } from '@ionic-native/gyroscope';

@Component({
    templateUrl: 'hardware-integration-sensors.html'
})
export class HardwareIntegrationSensorsPage {

    private gyroscope_subscription: Subscription;

    constructor(
        private gyroscope: Gyroscope
    ) {}

    ionViewWillEnter(): void {

        console.log('subscribing to gyroscope stuff');

        this.gyroscope.getCurrent().then((orientation: GyroscopeOrientation) => {
            console.log('gyroscope.getCurrent() fired', orientation); // this never happens
        });

        this.gyroscope_subscription = this.gyroscope.watch().subscribe((orientation: GyroscopeOrientation) => {
            console.log('gyroscope.watch() fired', orientation); // this never happens
        });

    }

    ionViewWillLeave(): void {
        this.gyroscope_subscription.unsubscribe();
    }

}
1 Like

Try shaking your keyboard?

1 Like

Hey! Have you find any solutions to it? I’m currently having the same issue with the gyroscope + emulator.

in android studio version 3
android emulator v 27
while the emulator is running open the emulator settings in the red square

this screen will show up

Click on Virtual Sensors and you’ll get the following screen which will allow you
to change the rotation and move the device
use the sliders

and for @btribouillet, click on Battery on the left side

Battery Status is indeed working.

However the gyroscope does not output anything in console (following official ionic documentation).
I do indeed use android studio emulator to simulate the gyroscope. What is weird is that the gyroscope is working on real phone (iphone) ;).