Giter Club home page Giter Club logo

plugin.maui.pedometer's Introduction

Plugin.Maui.Pedometer

Plugin.Maui.Pedometer provides the ability to read the device pedometer in your .NET MAUI application. This plugin currently only supports iOS and Android.

Install Plugin

NuGet

Available on NuGet.

Install with the dotnet CLI: dotnet add package Plugin.Maui.Pedometer, or through the NuGet Package Manager in Visual Studio.

API Usage

Plugin.Maui.Pedometer provides the Pedometer class that can be used to monitor the device pedometer and track the user's step count.

Permissions

Before you can start reading pedometer values, you will need to request the proper permissions on each platform.

iOS

On iOS, add the NSMotionUsageDescription key to your info.plist file. When declared, the permission will be requested automatically at runtime.

<key>NSMotionUsageDescription</key>
<string>This app wants to track your pedometer readings</string>

Android

On Android with API 29+, declare the ACTIVITY_RECOGNITION permissions in your AndroidManifest.xml file. This should be placed in the manifest node. You can also add this through the visual editor in Visual Studio.

The runtime permission is automatically requested by the plugin when Start() is called.

<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />

Dependency Injection

You will first need to register the Pedometer with the MauiAppBuilder following the same pattern that the .NET MAUI Essentials libraries follow.

builder.Services.AddSingleton(Pedometer.Default);

You can then enable your classes to depend on IPedometer as per the following example.

public class StepCounterViewModel
{
    readonly IPedometer pedometer;

    public StepCounterViewModel(IPedometer pedometer)
    {
        this.pedometer = pedometer;
    }

    public void StartCounting()
    {
        pedometer.ReadingChanged += (sender, reading) =>
        {
            Console.WriteLine(reading.NumberOfSteps);
        };

        pedometer.Start();
    }
}

Straight usage

Alternatively if you want to skip using the dependency injection approach you can use the Pedometer.Default property.

public class StepCounterViewModel
{
    public void StartCounting()
    {
        pedometer.ReadingChanged += (sender, reading) =>
        {
            Console.WriteLine(reading.NumberOfSteps);
        };

        Pedometer.Default.Start();
    }
}

Pedometer

Once you have created a Pedometer you can interact with it in the following ways:

Events

ReadingChanged

Occurs when pedometer reading changes.

Properties

IsSupported

Gets a value indicating whether reading the pedometer is supported on this device.

IsMonitoring

Gets a value indicating whether the pedometer is actively being monitored.

Methods

Start()

Start monitoring for changes to the pedometer.

Stop()

Stop monitoring for changes to the pedometer.

plugin.maui.pedometer's People

Contributors

jfversluis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

plugin.maui.pedometer's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.