Shiny .NET v4.1 BETA - Linux, MacOS, & Blazor Support! TONS of new features and improvements across the board. Check It Out
Motion Activity
Getting Started
Section titled “Getting Started” Frameworks
.NET MAUI
Operating Systems
Android
iOS
Shiny provides cross-platform motion activity recognition, allowing your app to detect whether the user is walking, running, cycling, driving, or stationary.
- On iOS, this uses
CMMotionActivityManagerfrom the CoreMotion framework. - On Android, this uses Google Play Services Activity Recognition API.
Register motion activity recognition in MauiProgram.cs:
// Without a background delegateservices.AddMotionActivity();
// With a background delegate for processing activity changes in the backgroundservices.AddMotionActivity<MyMotionActivityDelegate>();Platform Permissions
Section titled “Platform Permissions”iOS: Add to Info.plist:
<key>NSMotionUsageDescription</key><string>This app uses motion activity to detect your movement type</string>Android: The ACTIVITY_RECOGNITION permission is required and will be requested automatically via RequestAccess().
Observing Motion Activity
Section titled “Observing Motion Activity”Foreground (Observable)
Section titled “Foreground (Observable)”Use WhenReading() to observe activity changes in the UI:
public class MyViewModel : IDisposable{ readonly IMotionActivityManager activityManager; IDisposable? sub;
public MyViewModel(IMotionActivityManager activityManager) { this.activityManager = activityManager; }
public async Task Start() { var access = await this.activityManager.RequestAccess(); if (access != AccessState.Available) return;
await this.activityManager.StartListener();
this.sub = this.activityManager .WhenReading() .Subscribe(reading => { // reading.Activity → MotionActivityType (Walking, Running, Cycling, etc.) // reading.Confidence → MotionActivityConfidence (Low, Medium, High) // reading.Timestamp → DateTimeOffset }); }
public async Task Stop() { this.sub?.Dispose(); await this.activityManager.StopListener(); }
public void Dispose() => this.sub?.Dispose();}Background (Delegate)
Section titled “Background (Delegate)”Implement IMotionActivityDelegate for processing activity changes even when the app is backgrounded:
public class MyMotionActivityDelegate : IMotionActivityDelegate{ readonly ILogger<MyMotionActivityDelegate> logger;
public MyMotionActivityDelegate(ILogger<MyMotionActivityDelegate> logger) { this.logger = logger; }
public Task OnReading(MotionActivityReading reading) { this.logger.LogInformation( "Activity: {Activity}, Confidence: {Confidence}", reading.Activity, reading.Confidence ); return Task.CompletedTask; }}Register the delegate:
services.AddMotionActivity<MyMotionActivityDelegate>();API Reference
Section titled “API Reference”IMotionActivityManager
Section titled “IMotionActivityManager”| Member | Return Type | Description |
|---|---|---|
IsListening | bool | Whether the manager is currently listening |
GetCurrentStatus() | AccessState | Get current permission status without prompting |
RequestAccess() | Task<AccessState> | Request permission to use motion activity |
GetLastReading() | IObservable<MotionActivityReading?> | Get the last known reading |
WhenReading() | IObservable<MotionActivityReading> | Observable stream of activity changes |
StartListener() | Task | Start listening for activity changes |
StopListener() | Task | Stop listening for activity changes |
MotionActivityType
Section titled “MotionActivityType”| Value | Description |
|---|---|
Unknown | Activity could not be determined |
Stationary | Device is not moving |
Walking | User is walking |
Running | User is running |
Cycling | User is cycling |
Automotive | User is in a vehicle |
MotionActivityConfidence
Section titled “MotionActivityConfidence”| Value | Description |
|---|---|
Low | Low confidence in the detected activity |
Medium | Medium confidence |
High | High confidence |
AI Coding Assistant
Section titled “AI Coding Assistant”Step 1 — Add the marketplace:
claude plugin marketplace add shinyorg/skills Step 2 — Install the plugin:
claude plugin install shiny-client@shiny Step 1 — Add the marketplace:
copilot plugin marketplace add https://github.com/shinyorg/skills Step 2 — Install the plugin:
copilot plugin install shiny-client@shiny