registerListener method

Future<EventChannel> registerListener(
  1. Sensor sensor,
  2. {int samplingPeriodUs,
  3. int maxReportLatencyUs}
)

Registers a SensorEvent listener for the given sensor at the given sampling frequency and the given maximum reporting latency.

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

Implementation

static Future<EventChannel> registerListener(final Sensor sensor,
    {int samplingPeriodUs, int maxReportLatencyUs}) async {
  assert(Platform.isAndroid);
  assert(sensor.key != null);
  final request = <String, dynamic>{
    'key': sensor.key,
    'samplingPeriodUs': samplingPeriodUs,
    'maxReportLatencyUs': maxReportLatencyUs,
  };
  final channelID = await _channel.invokeMethod('registerListener', request);
  return (channelID != null)
      ? EventChannel('flutter_android/SensorManager/$channelID')
      : null;
}