Ex:
1. Tilting the phone to the left about 12* -> my application will show 12*.
- Tilting the phone to the right about 15* -> my application will show 15*
How to do that on Xamarin Android(Calulate xyz)
Ex:
1. Tilting the phone to the left about 12* -> my application will show 12*.
How to do that on Xamarin Android(Calulate xyz)
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);
}
}