@@ -88,11 +88,12 @@ import ActivityRecognition from 'react-native-activity-recognition'
88
88
...
89
89
90
90
// Start activity detection
91
- ActivityRecognition.start (1000 ) // detection interval in ms
91
+ const detectionIntervalMillis = 1000
92
+ ActivityRecognition.start (detectionIntervalMillis )
92
93
93
94
// Subscribe to updates
94
95
this.unsubscribe = ActivityRecognition.subscribe (detectedActivities => {
95
- const mostProbable = ActivityRecognition . getMostProbableActivity ( detectedActivities ) // => { type: 'STILL', confidence: 77 }
96
+ const mostProbableActivity = detectedActivities . sorted [ 0 ]
96
97
})
97
98
98
99
...
@@ -102,7 +103,7 @@ ActivityRecognition.stop()
102
103
this.unsubscribe ()
103
104
```
104
105
105
- `detectedActivities` is an object with keys for each detected activity, each of which have an integer value from 0 to 100
106
+ `detectedActivities` is an object with keys for each detected activity, each of which have an integer percentage ( 0 - 100 )
106
107
indicating the likelihood that the user is performing this activity. For example:
107
108
108
109
```js
@@ -114,6 +115,22 @@ indicating the likelihood that the user is performing this activity. For example
114
115
}
115
116
```
116
117
118
+ Additionally , the `detectedActivities. sorted` getter is provided which returns an array of activities, ordered by their
119
+ confidence value:
120
+
121
+ ```js
122
+ [
123
+ { type: ' STILL' , confidence: 77 },
124
+ { type: ' IN_VEHICLE' , confidence: 15 },
125
+ { type: ' ON_FOOT' , confidence: 8 },
126
+ { type: ' WALKING' , confidence: 8 },
127
+ ]
128
+ ```
129
+
130
+ Because the activities are sorted by confidence level, the first value will be the one with the highest probability.
131
+ Note that ON_FOOT and WALKING are related but won' t always have the same value. I have never seen WALKING with a higher
132
+ confidence than ON_FOOT, but it may happen that WALKING comes before ON_FOOT in the array if they have the same value.
133
+
117
134
The following activity types are supported:
118
135
119
136
- IN_VEHICLE
@@ -132,15 +149,11 @@ Starts listening for activity updates. The detectionIntervalMillis is passed to
132
149
133
150
### `subscribe(callback: Function): Function`
134
151
Subscribes a callback function to be invoked on each activity update. Returns a function which can be called in order to unsubscribe.
135
- The update callback will be invoked with an object representing the detected activities and their confidence percentage .
152
+ The update callback will be invoked with the detectedActivities object .
136
153
137
154
### `stop(): void`
138
155
Stops listening for activity updates.
139
156
140
- ### `getMostProbableActivity (detectedActivities : Object ): Object`
141
- Util function to determine the most probable activity `type` and its `confidence` percentage based on the detectedActivities object used in the `subscribe` callback.
142
- For example: `{ type: ' STILL' , confidence: 77 }`
143
-
144
157
## Credits / prior art
145
158
146
159
The following projects were very helpful in developing this library:
0 commit comments