Motion Activity

Motion activity is a great mechanism for querying for how your user is moving. This set of API's works slightly different than other APIs in Shiny. iOS does not allow watching for these events in the background, but it allows you to query by date/time range (careful, the query can yield A LOT of data). In order to emulate this same queryable mechanism on Android, Shiny starts up a broadcast receiver that continually receives events and stores them in a local SQLite database.

The events captured by this API are

  • Automotive
  • Stationary
  • Walking
  • Running
  • Cycling

|Area|Info| |---|---| |Description|| |Service|Shiny.Locations.IMotionActivityManager| |NuGet|| |Static Generated Class|ShinyMotionActivity|

using Microsoft.Extensions.DependencyInjection;
using Shiny;

namespace YourNamespace
    public class YourShinyStartup : ShinyStartup
        public override void ConfigureServices(IServiceCollection services, IPlatform platform)

Minimum Version: 8.0


<?xml version="1.0" encoding="utf-8" ?>
<manifest xmlns:android="" android:versionCode="1" android:versionName="1.0" package="" android:installLocation="preferExternal">
    <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />

Minimum Version: 10


<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE plist PUBLIC " -//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
    <string>Say something useful here that your users will understand</string>


You can either inject this service or resolve it via the Shiny.ShinyHost.Resolve method. The interface being used here is Shiny.Locations.IMotionActivity

Make sure before you get going to check support on your OS using

if (motionActivity.IsSupport) {


Here are the main enums you'll be working with

public enum MotionActivityType
    Unknown = 0,
    Stationary = 1,
    Walking = 2,
    Running = 4,
    Automotive = 8,
    Cycling = 16

public enum MotionActivityConfidence


The main part of this API is the querying which is extrememly straightforward. Careful - if your time range is wide, this method will easily return 1000s of rows.

var data = await motionActivity.Query(startDateTime, endDateTime);
foreach (var record in data) {
    //record.Types.HasEnum() // types is a flags enum as shown above
    // record.Confidence

monitoring (foreground only)

You can monitor events changes while your app is in the foreground using the following

    .Subscribe(x => {
        // you will get the same type of event as the query
        // make sure to pop on the main thread here :)