kprimice / react-native-sensor-manager

Native sensors access for react-native
239 stars 73 forks source link

Gyroscope event not triggered #25

Open herdani opened 7 years ago

herdani commented 7 years ago

The listener 'Gyroscope' is never triggered, I have no errors at all, but nothing never happens. I suppose my code is Ok since all other sensors are working well. Tried on a Samsung and a Sony device. Any idea ?

import React, {DeviceEventEmitter} from 'react-native';

var mSensorManager = require('NativeModules').SensorManager;
mSensorManager.startGyroscope(100);
DeviceEventEmitter.addListener('Gyroscope', function(data) {
  // Got never here
});
herdani commented 7 years ago

Hint: While trying to debug (don't know Android nor Java, so quite hard), I found out that, in file react-native-sensor-manager/android/src/main/java/com/sensormanager/GyroscopeRecord.java

if ((mGyroscope = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE)) != null) {

always returns null ...

kennethjiang commented 7 years ago

What's the solution?

I have the same problem. In my situation Orientation event is never triggered either, which could be related.

kennethjiang commented 7 years ago

Never mind. It turns out my Android device doesn't have a gyro or magnetometer. :(