void InitSensor() { sensorManager = Application.Context.GetSystemService(Context.SensorService) as SensorManager; stopwatch = new Stopwatch(); stopwatch.Restart(); isFirstRun = true; sensorIsAccelerating = true; // moving forward, not backward if (sensorManager != null) { sensor = sensorManager.GetDefaultSensor(SensorType.Accelerometer); DeviceDebugAndroid.LogToFileStatic("accelerometer sensor requested"); if (sensor != null) { // SensorDelay.Ui = approx 15 Hz = every 66 milliseconds // SensorDelay.Game = approx 50 Hz = every 20 milliseconds sensorManager.RegisterListener(this, sensor, SensorDelay.Game); status = "sensor init"; DeviceDebugAndroid.LogToFileStatic("accelerometer sensor init ok"); } else { status = "sensor not enabled"; DeviceDebugAndroid.LogToFileStatic("ERROR: accelerometer sensor is null"); } } else { status = "sensor manager not enabled"; DeviceDebugAndroid.LogToFileStatic("ERROR: accelerometer sensorManager is null"); } }
void InitSensor() { locationManager = Application.Context.GetSystemService(Context.LocationService) as LocationManager; DeviceDebugAndroid.LogToFileStatic("gps sensor requested"); if (locationManager != null) { if (locationManager.IsProviderEnabled(LocationManager.GpsProvider)) { locationManager.RequestLocationUpdates(LocationManager.GpsProvider, 0, 0, this); locationManager.AddGpsStatusListener(this); location = locationManager.GetLastKnownLocation(LocationManager.GpsProvider); status = IDeviceGpsStatus.Requested; DeviceDebugAndroid.LogToFileStatic("gps sensor init ok"); } else { status = IDeviceGpsStatus.Disabled; DeviceDebugAndroid.LogToFileStatic("ERROR: gps sensor not enabled"); } } else { status = IDeviceGpsStatus.Disabled; DeviceDebugAndroid.LogToFileStatic("ERROR: gps locationManager is null"); } }