public override void Initialize() { base.Initialize(); var viewListener = new ViewListener(this); gameView = Game.Context.Control; gameView.SetOnTouchListener(viewListener); gameView.SetOnKeyListener(viewListener); gameView.Resize += GameViewOnResize; GameViewOnResize(null, EventArgs.Empty); // Get the android sensors sensorManager = (SensorManager)PlatformAndroid.Context.GetSystemService(Context.SensorService); androidAccelerometer = sensorManager.GetDefaultSensor(SensorType.Accelerometer); androidGyroscope = sensorManager.GetDefaultSensor(SensorType.Gyroscope); androidUserAcceleration = sensorManager.GetDefaultSensor(SensorType.LinearAcceleration); androidGravity = sensorManager.GetDefaultSensor(SensorType.Gravity); androidRotationVector = sensorManager.GetDefaultSensor(SensorType.RotationVector); // Determine which sensor is available on the device Accelerometer.IsSupported = androidAccelerometer != null; Compass.IsSupported = androidRotationVector != null; Gyroscope.IsSupported = androidGyroscope != null; UserAcceleration.IsSupported = androidUserAcceleration != null; Gravity.IsSupported = androidGravity != null; Orientation.IsSupported = androidRotationVector != null; }
/// <summary> /// Initializes a new instance of the DeviceMotionImplementation class. /// </summary> public DeviceMotionImplementation() : base() { sensorManager = (SensorManager)Application.Context.GetSystemService(Context.SensorService); sensorAccelerometer = sensorManager.GetDefaultSensor(SensorType.Accelerometer); sensorGyroscope = sensorManager.GetDefaultSensor(SensorType.Gyroscope); sensorMagnetometer = sensorManager.GetDefaultSensor(SensorType.MagneticField); sensorCompass = sensorManager.GetDefaultSensor(SensorType.Orientation); sensorStatus = new Dictionary<MotionSensorType, bool>(){ { MotionSensorType.Accelerometer, false}, { MotionSensorType.Gyroscope, false}, { MotionSensorType.Magnetometer, false}, { MotionSensorType.Compass,false} }; }
public SensorReadingTest() { sensorManager = (SensorManager)Android.App.Application.Context.GetSystemService(Android.Content.Context.SensorService); sensorAccelerometer = sensorManager.GetDefaultSensor(SensorType.Accelerometer); sensorMagnetometer = sensorManager.GetDefaultSensor(SensorType.MagneticField); sensorGravity = sensorManager.GetDefaultSensor(SensorType.Gravity); sensorGyroscope = sensorManager.GetDefaultSensor(SensorType.Gyroscope); sensorStatus = new Dictionary<SensorType, bool>() { { SensorType.Accelerometer, false}, { SensorType.MagneticField, false}, { SensorType.Gravity, false}, { SensorType.Gyroscope, false} }; }
public SimulationView (Context context, SensorManager sensorManager, IWindowManager window) : base (context) { Bounds = new PointF (); // Get an accelorometer sensor sensor_manager = sensorManager; accel_sensor = sensor_manager.GetDefaultSensor (SensorType.Accelerometer); // Calculate screen size and dpi var metrics = new DisplayMetrics (); window.DefaultDisplay.GetMetrics (metrics); meters_to_pixels_x = metrics.Xdpi / 0.0254f; meters_to_pixels_y = metrics.Ydpi / 0.0254f; // Rescale the ball so it's about 0.5 cm on screen var ball = BitmapFactory.DecodeResource (Resources, Resource.Drawable.Ball); var dest_w = (int)(BALL_DIAMETER * meters_to_pixels_x + 0.5f); var dest_h = (int)(BALL_DIAMETER * meters_to_pixels_y + 0.5f); ball_bitmap = Bitmap.CreateScaledBitmap (ball, dest_w, dest_h, true); // Load the wood background texture var opts = new BitmapFactory.Options (); opts.InDither = true; opts.InPreferredConfig = Bitmap.Config.Rgb565; wood_bitmap = BitmapFactory.DecodeResource (Resources, Resource.Drawable.Wood, opts); wood_bitmap2 = BitmapFactory.DecodeResource (Resources, Resource.Drawable.Wood, opts); display = window.DefaultDisplay; particles = new ParticleSystem (this); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); illuminationView = FindViewById <TextView> (Resource.Id.Illumination); historyView = FindViewById <TextView> (Resource.Id.History); manager = (SensorManager)GetSystemService(SensorService); lightSensor = manager.GetDefaultSensor(SensorType.Light); var executeButton = FindViewById <Button> (Resource.Id.Execute); executeButton.Click += (sender, e) => { detectable = !detectable; executeButton.Text = detectable ? "停止" : "開始"; if (detectable) { RegisterLightListener(); } else { UnRegisterLightListener(); } }; var clearButton = FindViewById <Button> (Resource.Id.Clear); clearButton.Click += (sender, e) => historyView.Text = ""; }
public void GetSpeed() { // Register this as a listener with the underlying service. sensorManager = (Android.Hardware.SensorManager)Forms.Context.GetSystemService(Context.SensorService); sensor = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.Accelerometer); sensorManager.RegisterListener(this, sensor, Android.Hardware.SensorDelay.Game); }
partial void Start() { this.sensorManager = Application.Context.GetSystemService(Context.SensorService) as SensorManager; this.accelerometer = sensorManager.GetDefaultSensor(SensorType.Accelerometer); this.sensorManager.RegisterListener(this, accelerometer, this.delay); }
public void Initialize() { _sensorManager = (SensusServiceHelper.Get() as AndroidSensusServiceHelper).Service.GetSystemService(global::Android.Content.Context.SensorService) as SensorManager; _sensor = _sensorManager.GetDefaultSensor(_sensorType); if (_sensor == null) throw new Exception("No sensors present for sensor type " + _sensorType); }
partial void Start() { this.sensorManager = Application.Context.GetSystemService(Context.SensorService) as SensorManager; this.gyroscope = sensorManager.GetDefaultSensor(SensorType.Gyroscope); this.sensorManager.RegisterListener(this, this.gyroscope, this.delay); }
// Initialization of the Activity after it is first created. Must at least // call {@link android.app.Activity#setContentView setContentView()} to // describe what is to be displayed in the screen. protected override void OnCreate(Bundle savedInstanceState) { // Be sure to call the base class. base.OnCreate (savedInstanceState); sensor_manager = (SensorManager)GetSystemService (SensorService); graph_view = new GraphView (this.BaseContext); SetContentView (graph_view); var accel = sensor_manager.GetDefaultSensor (SensorType.Accelerometer); var mag = sensor_manager.GetDefaultSensor (SensorType.MagneticField); var ori = sensor_manager.GetDefaultSensor (SensorType.Orientation); sensor_manager.RegisterListener (graph_view, accel, SensorDelay.Fastest); sensor_manager.RegisterListener (graph_view, mag, SensorDelay.Fastest); sensor_manager.RegisterListener (graph_view, ori, SensorDelay.Fastest); }
public Implementation() { sensorManager = (SensorManager)Android.App.Application.Context.GetSystemService(Android.Content.Context.SensorService); sensorAccelerometer = sensorManager.GetDefaultSensor(SensorType.Accelerometer); sensorGravimeter = sensorManager.GetDefaultSensor(SensorType.Gravity); sensorGyroscope = sensorManager.GetDefaultSensor(SensorType.Gyroscope); sensorMagnetometer = sensorManager.GetDefaultSensor(SensorType.MagneticField); sensorOrientation = sensorManager.GetDefaultSensor(SensorType.Orientation); sensorStatus = new Dictionary<DeviceSensorType, bool>() { { DeviceSensorType.Accelerometer, false}, { DeviceSensorType.Gravimeter, false}, { DeviceSensorType.Gyroscope, false}, { DeviceSensorType.Magnetometer, false}, { DeviceSensorType.Orientation, false } }; }
public static void SetupAccelerometer() { _sensorManger = (SensorManager)Game.contextInstance.GetSystemService(Context.SensorService); _sensor = _sensorManger.GetDefaultSensor(SensorType.Accelerometer); if (_sensor != null) { _state = new AccelerometerState { IsConnected = true }; _sensorManger.RegisterListener(new SensorListener(), _sensor, SensorDelay.Game); } else _state = new AccelerometerState { IsConnected = false }; }
public static void SetupAccelerometer() { _sensorManger = (SensorManager)Game.Activity.GetSystemService(Context.SensorService); _sensor = _sensorManger.GetDefaultSensor(SensorType.Accelerometer); if (_sensor != null) { _state = new AccelerometerState { IsConnected = true }; } else _state = new AccelerometerState { IsConnected = false }; }
public void SetSensorListener(ISensorListener l) { listener = l; if (listener != null) { sensorManager = (SensorManager) context.GetSystemService(Context.SensorService); sensorManager.RegisterListener(this, sensorManager.GetDefaultSensor(SensorType.Accelerometer), SensorDelay.Game); } else { if (sensorManager != null) { sensorManager.UnregisterListener(this); sensorManager = null; } } }
public Implementation() { sensorManager = (SensorManager)Android.App.Application.Context.GetSystemService(Context.SensorService); sensorAccelerometer = sensorManager.GetDefaultSensor(SensorType.Accelerometer); sensorGravimeter = sensorManager.GetDefaultSensor(SensorType.Gravity); sensorGyroscope = sensorManager.GetDefaultSensor(SensorType.Gyroscope); sensorMagnetometer = sensorManager.GetDefaultSensor(SensorType.MagneticField); sensorOrientation = sensorManager.GetDefaultSensor(SensorType.Orientation); //Instead of using raw data from the orientation sensor, we recommend that you use the getRotationMatrix() method in conjunction with the getOrientation() method to compute orientation values.You can also use the remapCoordinateSystem() method to translate the orientation values to your application's frame of reference. sensorStatus = new Dictionary<DeviceSensorType, bool>() { { DeviceSensorType.Accelerometer, false}, { DeviceSensorType.Gravimeter, false}, { DeviceSensorType.Gyroscope, false}, { DeviceSensorType.Magnetometer, false}, { DeviceSensorType.Orientation, false }, { DeviceSensorType.OrientationRaw, false} }; isOrientationRawActivated = false; }
protected override void OnCreate(Bundle bundle) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(bundle); global::Xamarin.Forms.Forms.Init(this, bundle); LoadApplication(new App()); mSensorManager = GetSystemService(Android.Content.Context.SensorService) as Android.Hardware.SensorManager; mRotationVectorSensor = mSensorManager.GetDefaultSensor(Android.Hardware.SensorType.RotationVector); mGeomagneticRotationVectorSensor = mSensorManager.GetDefaultSensor(SensorType.GeomagneticRotationVector); mAccelerometerSensor = mSensorManager.GetDefaultSensor(SensorType.Accelerometer); mMagneticFieldSensor = mSensorManager.GetDefaultSensor(SensorType.MagneticField); mSensorManager.RegisterListener(this, mRotationVectorSensor, SensorDelay.Normal); mSensorManager.RegisterListener(this, mGeomagneticRotationVectorSensor, SensorDelay.Normal); mSensorManager.RegisterListener(this, mAccelerometerSensor, SensorDelay.Normal); mSensorManager.RegisterListener(this, mMagneticFieldSensor, SensorDelay.Normal); }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); SetContentView (Resource.Layout.Sensors); trackButton = FindViewById<Button> (Resource.Id.trackButton); stepCount = FindViewById<TextView> (Resource.Id.stepCount); // create a sensor manager to schedule batches of sensor data senMgr = (SensorManager) GetSystemService (SensorService); // update state from orientation change if (bundle != null) { count = bundle.GetFloat ("step_count", 0); if (bundle.GetBoolean ("visible", false)) { visible = true; stepCount.Text = count.ToString (); } Log.Debug(GetType().FullName, "Recovered instance state"); } // This button gets the user's step count since the last time the device was rebooted trackButton.Click += (o, e) => { // get the step counter sensor via the SensorManager counter = senMgr.GetDefaultSensor (SensorType.StepCounter); // button's been clicked, so counter visibility gets set to true visible = true; // This sensor is only available on Nexus 5 and Moto X at time of writing // The following line will check if the sensor is available explicitly: bool counterAvailabe = PackageManager.HasSystemFeature(PackageManager.FeatureSensorStepCounter); Log.Info("SensorManager", "Counter available"); if (counterAvailabe && counter != null) { // Set sensor delay to normal, the default rate for batching sensor data senMgr.RegisterListener(this, counter, SensorDelay.Normal); Toast.MakeText(this,"Count sensor started",ToastLength.Long).Show(); } else { Toast.MakeText(this, "Count sensor unavailable", ToastLength.Long).Show(); } }; }
public void Start() { if (_accelerometer != null) { throw new MvxException("Accelerometer already started"); } var globals = Mvx.Resolve<IMvxAndroidGlobals>(); _sensorManager = (SensorManager) globals.ApplicationContext.GetSystemService(Context.SensorService); if (_sensorManager == null) throw new MvxException("Failed to find SensorManager"); _accelerometer = _sensorManager.GetDefaultSensor(SensorType.Accelerometer); if (_accelerometer == null) throw new MvxException("Failed to find Accelerometer"); // It is not necessary to get accelerometer events at a very high // rate, by using a slower rate (SENSOR_DELAY_UI), we get an // automatic low-pass filter, which "extracts" the gravity component // of the acceleration. As an added benefit, we use less power and // CPU resources. _sensorManager.RegisterListener(this, _accelerometer, SensorDelay.Ui); }
protected override void OnCreate(Bundle bundle) { base.OnCreate (bundle); // Set our view from the "main" layout resource SetContentView (Resource.Layout.Main); _sensorManager = (SensorManager) GetSystemService(Context.SensorService); _sensorManager.RegisterListener (this, _sensorManager.GetDefaultSensor (SensorType.Accelerometer), SensorDelay.Normal); this._shakeHelper = new ShakeHelper (SensorManager.GravityEarth, SensorManager.GravityEarth); _decisions = new List<string> (); DecisionAdapter = new Adapters.DecisionAdapter (this, _decisions); ListView decisionList = FindViewById<ListView> (Resource.Id.lvDecisions); decisionList.Adapter = DecisionAdapter; decisionList.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) => { RemoveDecision(e.Position); }; Button btnAddDecision = FindViewById<Button> (Resource.Id.btnAddDecision); btnAddDecision.Click += delegate { AddDecision(); InputMethodManager inputManager = (InputMethodManager) GetSystemService(Context.InputMethodService); inputManager.HideSoftInputFromWindow(CurrentFocus.WindowToken, HideSoftInputFlags.NotAlways); }; Button btnDecide = FindViewById<Button> (Resource.Id.btnDecide); btnDecide.Click += delegate { MakeDecision(); }; }
public LocListener(LocationManager lm, SensorManager sm) : base() { // Get LocationManager locManager = lm; var locationCriteria = new Criteria () { Accuracy = global::Android.Locations.Accuracy.Fine, AltitudeRequired = true, PowerRequirement = Power.Low }; locationProvider = locManager.GetBestProvider(locationCriteria, true); if (locationProvider == null) throw new Exception("No location provider found"); List<String> providers = locManager.GetProviders(true) as List<String>; // Loop over the array backwards, and if you get an accurate location, then break out the loop Location loc = null; if (providers != null) { for (int i = providers.Count - 1; i >= 0; i--) { loc = locManager.GetLastKnownLocation(providers[i]); if (loc != null) break; } } if (loc != null) { lat = loc.Latitude; lon = loc.Longitude; alt = loc.Altitude; accuracy = loc.Accuracy; } sensorManager = sm; accelerometer = sensorManager.GetDefaultSensor(SensorType.Accelerometer); magnetometer = sensorManager.GetDefaultSensor(SensorType.MagneticField); }
protected override void OnElementChanged(ElementChangedEventArgs<Page> e) { base.OnElementChanged (e); mainView = e.NewElement as MainView; sensorManager = (SensorManager)Context.GetSystemService (Context.SensorService); sensor = sensorManager.GetDefaultSensor (Android.Hardware.SensorType.Accelerometer); sensorManager.RegisterListener (this, sensor, Android.Hardware.SensorDelay.Game); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.AccelerometerMain); //Normal Accelerometer (Pure Hardware) accelStatus = (TextView)FindViewById(Resource.Id.accelStatus); accelStrength = (TextView)FindViewById(Resource.Id.accelStrength); accelX = (TextView)FindViewById(Resource.Id.accelX); accelY = (TextView)FindViewById(Resource.Id.accelY); accelZ = (TextView)FindViewById(Resource.Id.accelZ); //Linear Accelerometer (Software Adjusted) linearStatus = (TextView)FindViewById(Resource.Id.linearStatus); linearStrength = (TextView)FindViewById(Resource.Id.linearStrength); linearX = (TextView)FindViewById(Resource.Id.linearX); linearY = (TextView)FindViewById(Resource.Id.linearY); linearZ = (TextView)FindViewById(Resource.Id.linearZ); //GPS gpsStatus = (TextView)FindViewById(Resource.Id.gpsStatus); gpsProvider = (TextView)FindViewById(Resource.Id.gpsProvider); gpsLatitude = (TextView)FindViewById(Resource.Id.gpsLatitude); gpsLongitude = (TextView)FindViewById(Resource.Id.gpsLongitude); gpsSpeed = (TextView)FindViewById(Resource.Id.gpsSpeed); InitalizeLocationManager(); //List<Sensor> deviceSensors = new List<Sensor>(mSensorManager.GetSensorList(SensorType.All)); //Sensor Initializations mSensorManager = (SensorManager)GetSystemService(Context.SensorService); if(mSensorManager.GetDefaultSensor(SensorType.Accelerometer) != null) { accelStatus.Text = "EXISTS"; mSensor = mSensorManager.GetDefaultSensor(SensorType.Accelerometer); } else { accelStatus.Text = "NOT AVAILABLE"; } if (mSensorManager.GetDefaultSensor(SensorType.LinearAcceleration) != null) { linearStatus.Text = "EXISTS"; mLinearSensor = mSensorManager.GetDefaultSensor(SensorType.LinearAcceleration); } else { linearStatus.Text = "NOT AVAILABLE"; } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.MotionStopMain); //Speed and Accelerometer UI data accelX = (TextView)FindViewById(Resource.Id.blackoutAccelX); accelY = (TextView)FindViewById(Resource.Id.blackoutAccelY); accelZ = (TextView)FindViewById(Resource.Id.blackoutAccelZ); threshold = (TextView)FindViewById(Resource.Id.threshold); blackout = (LinearLayout)FindViewById(Resource.Id.blackout); currentSpeed = (TextView)FindViewById(Resource.Id.currentSpeed); ambientLight = (TextView)FindViewById(Resource.Id.ambientLight); //LightSensor Changes overallLayout = (LinearLayout)FindViewById(Resource.Id.overallLayout); subLayout1 = (LinearLayout)FindViewById(Resource.Id.subLayout1); subLayout2 = (LinearLayout)FindViewById(Resource.Id.subLayout2); subLayout3 = (LinearLayout)FindViewById(Resource.Id.subLayout3); title1 = (TextView)FindViewById(Resource.Id.title1); title2 = (TextView)FindViewById(Resource.Id.title2); title3 = (TextView)FindViewById(Resource.Id.title3); //UI Switch to toggle driver distraction blackout feature blackoutOn = false; blackoutSwitch = (Switch)FindViewById(Resource.Id.gpsBlackoutSwitch); blackoutSwitch.CheckedChange += delegate(object sender, CompoundButton.CheckedChangeEventArgs e) { blackoutOn = blackoutSwitch.Checked; }; //Need this to initialize the location listener InitalizeLocationManager(); //Check for sensors mSensorManager = (SensorManager)GetSystemService(Context.SensorService); if (mSensorManager.GetDefaultSensor(SensorType.LinearAcceleration) != null) { mSensor = mSensorManager.GetDefaultSensor(SensorType.LinearAcceleration); } if (mSensorManager.GetDefaultSensor(SensorType.Light) != null) { mLightSensor = mSensorManager.GetDefaultSensor(SensorType.Light); } }
public Accelerometer(Context context) { _sensorManager = (SensorManager) context.GetSystemService(Context.SensorService); _sensor = _sensorManager.GetDefaultSensor(SensorType.Accelerometer); }
public SensorManager() : base() { sensorManager = (Android.Hardware.SensorManager)Android.App.Application.Context.GetSystemService(Context.SensorService); sensorAccelerometer = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.Accelerometer); sensorGyroscope = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.Gyroscope); sensorMagnetometer = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.MagneticField); sensorCompass = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.Orientation); sensorLight = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.Light); sensorPressure = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.Pressure); sensorProximity = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.Proximity); sensorLinearAcceleration = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.LinearAcceleration); sensorRotation = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.RotationVector); sensorGameRotation = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.GameRotationVector); sensorHumidity = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.RelativeHumidity); sensorAmbientTemperature = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.AmbientTemperature); sensorSignificantMotion = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.SignificantMotion); sensorStepDetector = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.StepDetector); sensorStepCounter = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.StepCounter); sensorHeartRate = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.HeartRate); sensorPose = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.Pose6dof); sensorStationary = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.StationaryDetect); sensorMotion = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.MotionDetect); sensorHeartBeat = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.HeartBeat); sensorStatus = new Dictionary <InteractClient.Sensors.SensorType, bool> { { InteractClient.Sensors.SensorType.AcceleroMeter, false }, { InteractClient.Sensors.SensorType.Gyroscope, false }, { InteractClient.Sensors.SensorType.MagnetoMeter, false }, { InteractClient.Sensors.SensorType.Compass, false }, { InteractClient.Sensors.SensorType.Light, false }, { InteractClient.Sensors.SensorType.Pressure, false }, { InteractClient.Sensors.SensorType.Proximity, false }, { InteractClient.Sensors.SensorType.LinearAcceleration, false }, { InteractClient.Sensors.SensorType.Rotation, false }, { InteractClient.Sensors.SensorType.GameRotation, false }, { InteractClient.Sensors.SensorType.Humidity, false }, { InteractClient.Sensors.SensorType.AmbientTemperature, false }, { InteractClient.Sensors.SensorType.SignificantMotion, false }, { InteractClient.Sensors.SensorType.StepDetector, false }, { InteractClient.Sensors.SensorType.StepCounter, false }, { InteractClient.Sensors.SensorType.HeartRate, false }, { InteractClient.Sensors.SensorType.Pose, false }, { InteractClient.Sensors.SensorType.Stationary, false }, { InteractClient.Sensors.SensorType.Motion, false }, { InteractClient.Sensors.SensorType.HeartBeat, false }, { InteractClient.Sensors.SensorType.Tilt, false }, }; TriggerEventListener = new SensorTriggerEventListener(); TriggerEventListener.Callback = OnSensorTrigger; }
public GPSListener(LocationManager lm, SensorManager sm, IWindowManager wm) : base() { // Get LocationManager _locManager = lm; _windowManager = wm; var locationCriteria = new Criteria () { Accuracy = global::Android.Locations.Accuracy.Fine, AltitudeRequired = true, PowerRequirement = Power.Low }; // locationProvider = _locManager.GetBestProvider(locationCriteria, true); locationProvider = LocationManager.GpsProvider; if (locationProvider == null) throw new Exception("No location provider found"); List<String> providers = _locManager.GetProviders(true) as List<String>; // Loop over the array backwards, and if you get an accurate location, then break out the loop GPSLocation loc = null; if (providers != null) { for (int i = providers.Count - 1; i >= 0; i--) { loc = new GPSLocation(_locManager.GetLastKnownLocation(providers[i])); if (loc != null) break; } } // If we have an old location, than use this as first location if (loc != null) { _location = new GPSLocation(loc); } else { _location = new GPSLocation(); } _sensorManager = sm; _orientationSensor = _sensorManager.GetDefaultSensor(SensorType.Orientation); _accelerometerSensor = _sensorManager.GetDefaultSensor(SensorType.Accelerometer); }
public bool Start () { if (this.Active) { return this.Active; } this.sensorManager = Application.Context.GetSystemService(Context.SensorService) as SensorManager; if (this.sensorManager == null) { this.OnException.Invoke (this, new Exception ("Unable to get sensor manager.")); return false; } this.accelerometer = sensorManager.GetDefaultSensor(SensorType.Accelerometer); Log.Info(this.accelerometer.ToString(), this.accelerometer.MaximumRange.ToString()); if (this.accelerometer == null) { this.sensorManager = null; this.OnException.Invoke (this, new Exception ("Unable to get Accelerometer.")); return false; } this.sensorManager.RegisterListener(this, accelerometer, Accelometer.Delay); return this.Active; }
public void Start() { _sensorManager = (SensorManager)Application.Context.GetSystemService(Android.App.Activity.SensorService); _sensorManager.RegisterListener(this, _sensorManager.GetDefaultSensor(SensorType.MagneticField), SensorDelay.Normal); _sensorManager.RegisterListener(this, _sensorManager.GetDefaultSensor(SensorType.Accelerometer), SensorDelay.Normal); }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); SetContentView (Resource.Layout.jj_layout); SetUpViews (); handler = new Handler (); jump_counter = Utils.GetCounterFromPreference (this); Window.AddFlags (WindowManagerFlags.KeepScreenOn); RenewTimer (); sensor_manager = (SensorManager)GetSystemService (Context.SensorService); sensor = sensor_manager.GetDefaultSensor (SensorType.Gravity); }