npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rn-motion-activity

v4.0.2

Published

React Native wrapper for the Activity Recognition API.

Downloads

1

Readme

react-native-activity-recognition

npm version

React Native wrapper for the Android Activity Recognition API and CMMotionActivity. It attempts to determine the user activity such as driving, walking, running and cycling. Possible detected activities for android are listed here and for iOS are listed here.

Installation

npm i -S react-native-activity-recognition

or with Yarn:

yarn add react-native-activity-recognition

Linking

Automatic

react-native link react-native-activity-recognition

IMPORTANT NOTE: You'll need to follow Step 4 for both iOS and Android of manual-linking

Manual

Make alterations to the following files in your project:

Android

  1. Add following lines to android/settings.gradle
...
include ':react-native-activity-recognition'
project(':react-native-activity-recognition').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-activity-recognition/android')
...
  1. Add the compile line to dependencies in android/app/build.gradle
...
dependencies {
    ...
    compile project(':react-native-activity-recognition')
    ...
}
  1. Add import and link the package in android/app/src/.../MainApplication.java
import com.xebia.activityrecognition.RNActivityRecognitionPackage;  // <--- add import

public class MainApplication extends Application implements ReactApplication {
    // ...
    @Override
    protected List<ReactPackage> getPackages() {
        return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
            // ...
            new RNActivityRecognitionPackage()                      // <--- add package
        );
    }
  1. Add activityrecognition service in android/app/src/main/AndroidManifest.xml
...
<application ...>
    ...
    <service android:name="com.xebia.activityrecognition.DetectionService"/>
    ...
</application>
...

iOS

  1. In the XCode's "Project navigator", right click on your project's Libraries folder ➜ Add Files to <...>
  2. Go to node_modulesreact-native-activity-recognitionios ➜ select RNActivityRecognition.xcodeproj
  3. Add RNActivityRecognition.a to Build Phases -> Link Binary With Libraries
  4. Add NSMotionUsageDescription key to your Info.plist with strings describing why your app needs this permission

Usage

import ActivityRecognition from 'react-native-activity-recognition'

...

// Subscribe to updates
this.unsubscribe = ActivityRecognition.subscribe(detectedActivities => {
  const mostProbableActivity = detectedActivities.sorted[0]
})

...

// Start activity detection
const detectionIntervalMillis = 1000
ActivityRecognition.start(detectionIntervalMillis)

...

// Stop activity detection and remove the listener
ActivityRecognition.stop()
this.unsubscribe()

Android

detectedActivities is an object with keys for each detected activity, each of which have an integer percentage (0-100) indicating the likelihood that the user is performing this activity. For example:

{
  ON_FOOT: 8,
  IN_VEHICLE: 15,
  WALKING: 8,
  STILL: 77
}

Additionally, the detectedActivities.sorted getter is provided which returns an array of activities, ordered by their confidence value:

[
  { type: 'STILL', confidence: 77 },
  { type: 'IN_VEHICLE', confidence: 15 },
  { type: 'ON_FOOT', confidence: 8 },
  { type: 'WALKING', confidence: 8 },
]

Because the activities are sorted by confidence level, the first value will be the one with the highest probability Note that ON_FOOT and WALKING are related but won't always have the same value. I have never seen WALKING with a higher confidence than ON_FOOT, but it may happen that WALKING comes before ON_FOOT in the array if they have the same value.

The following activity types are supported:

  • IN_VEHICLE
  • ON_BICYCLE
  • ON_FOOT
  • RUNNING
  • WALKING
  • STILL
  • TILTING
  • UNKNOWN

iOS

detectedActivities is an object with key to the detected activity with a confidence value for that activity given by CMMotionActivityManager. For example:

{
    WALKING: 2
}

detectedActivities.sorted getter will return it in the form of an array.

[
    {type: "WALKING", confidence: 2}
]

The following activity types are supported:

  • RUNNING
  • WALKING
  • STATIONARY
  • AUTOMOTIVE
  • CYCLING
  • UNKNOWN

Credits / prior art

The following projects were very helpful in developing this library:

  • https://github.com/googlesamples/android-play-location
  • https://bitbucket.org/timhagn/react-native-google-locations
  • https://github.com/facebook/react-native/blob/master/Libraries/Geolocation