0

Ex: 

1. Tilting the phone to the left about 12* -> my application will show 12*.

  1. Tilting the phone to the right about 15* -> my application will show 15*

How to do that on Xamarin Android(Calulate xyz)

  • Possible duplicate of [Android Compass that can Compensate for Tilt and Pitch](http://stackoverflow.com/questions/16317599/android-compass-that-can-compensate-for-tilt-and-pitch) – SushiHangover Dec 23 '16 at 15:54

1 Answers1

0

You can follow this work around to create your application . Demolink

The following is sample code.

public class MainActivity : Activity, ISensorEventListener
{
    private SensorManager mSensorManager;
    private Sensor mOrientation;
    private TextView _sensorTextView;
    static readonly object _syncLock = new object();
    public void OnAccuracyChanged(Sensor sensor, [GeneratedEnum] SensorStatus accuracy)
    {
        // do 
    }

    public void OnSensorChanged(SensorEvent e)
    {

        lock (_syncLock)
        {
            _sensorTextView.Text = string.Format("x={0:f}, y={1:f}, y={2:f}", e.Values[0], e.Values[1], e.Values[2]);
        }
    }
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        SetContentView(Resource.Layout.Main);
        mSensorManager = (SensorManager)GetSystemService(Context.SensorService);
        mOrientation = mSensorManager.GetDefaultSensor(SensorType.Orientation, true);
        _sensorTextView = FindViewById<TextView>(Resource.Id.accelerometer_text);
    }
    protected override void OnResume()
    {
        base.OnResume();
        mSensorManager.RegisterListener(this, mOrientation, SensorDelay.Normal);
    }
    protected override void OnPause()
    {
        base.OnPause();
        mSensorManager.UnregisterListener(this);
    }
}
Nico Zhu - MSFT
  • 25,823
  • 2
  • 12
  • 32