subscribe method

Future<Stream<SensorEvent>> subscribe(
  1. {int samplingPeriodUs,
  2. int maxReportLatencyUs}
)

Subscribes to this sensor's event stream.

See: https://developer.android.com/reference/android/hardware/SensorManager#registerListener(android.hardware.SensorEventListener,%20android.hardware.Sensor,%20int)

Implementation

Future<Stream<SensorEvent>> subscribe(
    {int samplingPeriodUs, int maxReportLatencyUs}) async {
  final events = await SensorManager.registerListener(this,
      samplingPeriodUs: samplingPeriodUs,
      maxReportLatencyUs: maxReportLatencyUs);
  return events.receiveBroadcastStream().map(
      (dynamic event) => _streamEventToSensorEvent(event.cast<double>()));
}