---
title: "How to Create a Mobile App That Monitors Accelerometer Data"
published_at: "2018-08-07T12:17:00+00:00"
modified_at: "2024-11-21T12:36:24+00:00"
url: "https://www.syncfusion.com/blogs/post/how-to-create-a-mobile-app-that-monitors-accelerometer-data"
excerpt: "This guest blog was written by Brandon Minnick, a Developer Advocate at Microsoft, specializing in Xamarin and Azure. Thanks to Xamarin.Essentials and Syncfusion’s circular gauge control, creating a mobile app that monitors accelerometer data has never been easier! Let’s take..."
taxonomy_category:
  - "Development"
  - "Mobile"
  - "Syncfusion"
taxonomy_post_tag:
  - "Android App"
  - "Brandon Minnick"
  - "Circular Gauge"
  - "circular gauge control"
  - "iOS app"
  - "Mobile App"
  - "Mobile App Development"
  - "Mobile Development"
  - "Syncfusion"
  - "Xamarin"
  - "Xamarin.Essentials"
  - "Xamarin.Forms"
  - "Xamarin.Forms App"
---

# How to Create a Mobile App That Monitors Accelerometer Data

[Syncfusion Guest Blogger](https://www.syncfusion.com/blogs/author/syncfusion-guest-blogger)

![Image](https://www.syncfusion.com/blogs/wp-content/uploads/2018/08/Tile_Acceleromater_e07dcee6.png)


*This guest blog was written by [Brandon Minnick](https://twitter.com/intent/user?user_id=3418408341)
, a Developer Advocate at Microsoft, specializing in Xamarin and Azure.*

Thanks to [Xamarin.Essentials](https://docs.microsoft.com/xamarin/essentials/?WT.mc_id=none-SyncFusionBlog-bramin)
 and [Syncfusion’s circular gauge](https://www.syncfusion.com/xamarin-ui-controls/circular-gauge)
 control, creating a mobile app that monitors accelerometer data has never been easier!

Let’s take a look at how to implement this control in a Xamarin.Forms app.

![Image](https://blog.syncfusion.com/wp-content/uploads/2018/08/43228875-b2c516ee-9017-11e8-9350-1016d7451a8f.gif)

**Walkthrough**

**1. Install NuGet Packages**

1. Install the [Syncfusion.Xamarin.SfGauge NuGet Package](https://www.nuget.org/packages/Syncfusion.Xamarin.SfGauge) into each project, this includes the Xamarin.iOS, Xamarin.Android, and the .NET Standard Project (if one is being used).
2. Install the [Xamarin.Essentials NuGet Package](https://www.nuget.org/packages/Xamarin.Essentials) into each project, this includes the Xamarin.iOS, Xamarin.Android, and the .NET Standard Project (if one is being used).

**2. Initialize Syncfusion on iOS**

To utilize the Syncfusion circular gauge, we first need to initialize it in AppDelegate.FinishedLaunching.

```
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
    ...

    public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary launchOptions)
    {
        ...

        Syncfusion.SfGauge.XForms.iOS.SfGaugeRenderer.Init();
        Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Your SyncFusion License Key");

        ...
    }
}
```

**3. Initialize Syncfusion on Android**

To utilize the Syncfusion circular gauge, we first need to initialize it in MainActivity.OnCreate:

```
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
    ...

    protected override void OnCreate(Bundle savedInstanceState)
    {
        ...

        Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Your SyncFusion License Key");

        ...
    }
}
```

**4. Reference Mono.Android.Export**

1. 
  1. In the Solution Explorer in the Android project, right-click on **References**.
  2. In the **References** menu, select ** Edit References**.

![Image](https://blog.syncfusion.com/wp-content/uploads/2018/08/43227940-0804184c-9015-11e8-8225-0b04b5507219.png)

1. In the **Edit References** window, select the ** Packages** tab.
2. In the **Packages** tab, locate Mono.Android.Export.
3. In the **Packages** tab, ensure Mono.Android.Export is checked.
4. In the **Edit References** window, click ** OK**.

![Image](https://blog.syncfusion.com/wp-content/uploads/2018/08/43227949-0c77ed0e-9015-11e8-8ff5-26d9f767e095.png)

**5. Implement SfCircularGauge in Xamarin.Forms**

This app requires three instances of the circular gauge control in our app, so let’s start by creating an implementation of SfCircularGauge.

```
public class CircularGaugeView : SfCircularGauge
{
    public CircularGaugeView(string headerText, double startValue, double endValue)
    {
        Pointer = new NeedlePointer { AnimationDuration = 0.5 };

        var header = new Header
        {
            Text = headerText,
            ForegroundColor = Color.Gray
        };

        var circularGaugeScale = new Scale
        {
            Interval = (endValue - startValue) / 10,
            StartValue = startValue,
            EndValue = endValue,
            ShowTicks = true,
            ShowLabels = true,
            Pointers = { Pointer },
            MinorTicksPerInterval = 4,
        };

        Scales = new ObservableCollection<Scale> { circularGaugeScale };
        Headers = new ObservableCollection<Header> { header };
    }

    public NeedlePointer Pointer { get; }
}
```

**6. Create Accelerometer Page**

In the Xamarin.Forms project, create a new class, AccelerometerPage.cs:

```
public class AccelerometerPage : ContentPage
{
    readonly CircularGaugeView xCircularGauge, yCircularGauge, zCircularGauge;

    public AccelerometerPage()
    {
        Icon = "Accelerometer";
        Title = "Accelerometer";

        xCircularGauge = new CircularGaugeView("X-Axis", -1, 1);
        yCircularGauge = new CircularGaugeView("Y-Axis", -1, 1);
        zCircularGauge = new CircularGaugeView("Z-Axis", -10, 10);

        var grid = new Grid
        {
            Margin = new Thickness(0, 20),
            RowDefinitions = {
                new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
                new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
                new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
            },
            ColumnDefinitions = {
                new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }
            }
        };
        grid.Children.Add(xCircularGauge, 0, 0);
        grid.Children.Add(yCircularGauge, 0, 1);
        grid.Children.Add(zCircularGauge, 0, 2);

        Content = grid;

        On<Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true);
    }

    protected override void OnAppearing()
    {
        base.OnAppearing();

        InitializeAccelerometer();
    }

    void InitializeAccelerometer()
    {
        try
        {
            Accelerometer.Start(SensorSpeed.Normal);
            Accelerometer.ReadingChanged += HandleAccelerometerReadingChanged;
        }
        catch (FeatureNotSupportedException)
        {
            Debug.WriteLine("Accelerometer Unavailable");
        }
    }

    void HandleAccelerometerReadingChanged(AccelerometerChangedEventArgs e)
    {
        Device.BeginInvokeOnMainThread(() =>
        {
            xCircularGauge.Pointer.Value = e.Reading.Acceleration.X;
            yCircularGauge.Pointer.Value = e.Reading.Acceleration.Y;
            zCircularGauge.Pointer.Value = e.Reading.Acceleration.Z;
        });
    }
}
```

**7. Set AccelerometerPage as the MainPage**

In App.cs, ensure that MainPage = new AccelerometerPage();

```
public class App : Xamarin.Forms.Application
{
    public App()
    {
        MainPage = new AccelerometerPage();
    }
}
```

**8. Launch the app on an iOS or Android Device**

**About the Author**

Brandon Minnick is a Developer Advocate at Microsoft, specializing in Xamarin and Azure. As a Developer Advocate, Brandon works closely with the mobile app community, helping them create 5-star apps and provide their feedback to the Microsoft product teams to help improve our tools and empower every person and every organization on the planet to achieve more.

[@TheCodeTraveler](https://twitter.com/intent/user?user_id=3418408341)

**Resources**

- [Xamarin](https://visualstudio.microsoft.com/xamarin/?WT.mc_id=none-SyncFusionBlog-bramin)
- [Xamarin.Essentials](https://docs.microsoft.com/xamarin/essentials/?WT.mc_id=none-SyncFusionBlog-bramin)
- [Azure IoT Central](https://azure.microsoft.com/services/iot-central/?WT.mc_id=none-SyncFusionBlog-bramin)
- [Syncfusion’s Circular Gauge](https://www.syncfusion.com/xamarin-ui-controls/circular-gauge)

*If you like this blog post, we think you’ll also like the following free e-books:*

*[Xamarin.Forms Succinctly](https://www.syncfusion.com/ebooks/xamarin_forms_succinctly)
  
 [Xamarin.Forms for macOS Succinctly](https://www.syncfusion.com/ebooks/xamarin_forms_for_mac_os_succinctly)
  
 [Writing Native Mobile Apps in a Functional Language Succinctly](https://www.syncfusion.com/ebooks/writing_native_mobile_apps_in_a_functional_language_succinctly)*
