Skip to content

Commit de28235

Browse files
committed
Updating README
1 parent 295b527 commit de28235

File tree

1 file changed

+39
-62
lines changed

1 file changed

+39
-62
lines changed

README.md

Lines changed: 39 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,27 @@ yarn add react-native-activity-recognition
2727

2828
## Linking
2929

30-
Make alterations to the following files in your project:
30+
### Automatic
3131

32-
### Android
32+
`react-native link react-native-activity-recognition`
3333

34-
#### `android/settings.gradle`
34+
IMPORTANT NOTE: You'll need to follow Step 4 for both iOS and Android of manual-linking
3535

36+
### Manual
37+
38+
Make alterations to the following files in your project:
39+
40+
#### Android
41+
42+
1. Add following lines to `android/settings.gradle`
3643
```gradle
3744
...
3845
include ':react-native-activity-recognition'
3946
project(':react-native-activity-recognition').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-activity-recognition/android')
4047
...
4148
```
4249

43-
#### `android/app/build.gradle`
44-
50+
2. Add the compile line to dependencies in `android/app/build.gradle`
4551
```gradle
4652
...
4753
dependencies {
@@ -51,8 +57,7 @@ dependencies {
5157
}
5258
```
5359

54-
#### `android/app/src/.../MainApplication.java`
55-
60+
3. Add import and link the package in `android/app/src/.../MainApplication.java`
5661
```java
5762
import com.xebia.activityrecognition.RNActivityRecognitionPackage; // <--- add import
5863

@@ -68,8 +73,7 @@ public class MainApplication extends Application implements ReactApplication {
6873
}
6974
```
7075

71-
#### `android/app/src/main/AndroidManifest.xml`
72-
76+
4. Add activityrecognition service in `android/app/src/main/AndroidManifest.xml`
7377
```xml
7478
...
7579
<application ...>
@@ -80,38 +84,42 @@ public class MainApplication extends Application implements ReactApplication {
8084
...
8185
```
8286

83-
### iOS
87+
#### iOS
8488

85-
Follow Step 1 and Step 2 [listed here][4]
89+
1. In the XCode's "Project navigator", right click on your project's Libraries folder ➜ `Add Files to <...>`
90+
2. Go to `node_modules` ➜ `react-native-activity-recognition` ➜ `ios` ➜ select `RNActivityRecognition.xcodeproj`
91+
3. Add `RNActivityRecognition.a` to `Build Phases -> Link Binary With Libraries`
92+
4. Add `NSMotionUsageDescription` key to your `Info.plist` with strings describing why your app needs this permission
8693

8794

8895
## Usage
8996

90-
### Android
91-
9297
```js
9398
import ActivityRecognition from 'react-native-activity-recognition'
9499

95100
...
96101

97-
// Start activity detection
98-
const detectionIntervalMillis = 1000
99-
ActivityRecognition.start(detectionIntervalMillis)
100-
101102
// Subscribe to updates
102103
this.unsubscribe = ActivityRecognition.subscribe(detectedActivities => {
103104
const mostProbableActivity = detectedActivities.sorted[0]
104105
})
105106

106107
...
107108

109+
// Start activity detection
110+
const detectionIntervalMillis = 1000
111+
ActivityRecognition.start(detectionIntervalMillis)
112+
113+
...
114+
108115
// Stop activity detection and remove the listener
109116
ActivityRecognition.stop()
110117
this.unsubscribe()
111118
```
112119

113-
`detectedActivities` is an object with keys for each detected activity, each of which have an integer percentage (0-100)
114-
indicating the likelihood that the user is performing this activity. For example:
120+
### Android
121+
122+
`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:
115123

116124
```js
117125
{
@@ -134,7 +142,7 @@ confidence value:
134142
]
135143
```
136144

137-
Because the activities are sorted by confidence level, the first value will be the one with the highest probability.
145+
Because the activities are sorted by confidence level, the first value will be the one with the highest probability
138146
Note that ON_FOOT and WALKING are related but won't always have the same value. I have never seen WALKING with a higher
139147
confidence than ON_FOOT, but it may happen that WALKING comes before ON_FOOT in the array if they have the same value.
140148
@@ -149,40 +157,21 @@ The following activity types are supported:
149157
- TILTING
150158
- UNKNOWN
151159
152-
#### Methods
153-
154-
##### `start(detectionIntervalMillis: number): void`
155-
Starts listening for activity updates. The detectionIntervalMillis is passed to ActivityRecognitionApi.requestActivityUpdates().
156-
157-
##### `subscribe(callback: Function): Function`
158-
Subscribes a callback function to be invoked on each activity update. Returns a function which can be called in order to unsubscribe.
159-
The update callback will be invoked with the detectedActivities object.
160-
161-
##### `stop(): void`
162-
Stops listening for activity updates.
163-
164160
### iOS
165-
```js
166-
import ActivityRecognition from 'react-native-activity-recognition'
167-
168-
...
169-
170-
// Subscribe to updates
171-
this.subscribe = ActivityRecognition.subscribe(detectedActivities => {
172-
173-
})
174-
175-
// Start activity detection
176-
const detectionIntervalMillis = 1000
177-
ActivityRecognition.start(detectionIntervalMillis)
178-
179-
...
180161
181-
// Stop activity detection and remove the listener
182-
ActivityRecognition.stop()
162+
`detectedActivities` is an object with key to the detected activity with a confidence value for that activity given by CMMotionActivityManager. For example:
163+
```js
164+
{
165+
WALKING: 2
166+
}
183167
```
184168
185-
`detectedActivities` is an object with keys for each detected activity with the value of probable activity as true.
169+
`detectedActivities.sorted` getter will return it in the form of an array.
170+
```js
171+
[
172+
{type: "WALKING", confidence: 2}
173+
]
174+
```
186175
187176
The following activity types are supported:
188177
@@ -193,18 +182,6 @@ The following activity types are supported:
193182
- CYCLING
194183
- UNKNOWN
195184
196-
#### Methods
197-
198-
##### `start(detectionIntervalMillis: number): void`
199-
Starts listening for activity updates. The detectionIntervalMillis is passed to ActivityRecognitionApi.requestActivityUpdates().
200-
201-
##### `subscribe(callback: Function): Function`
202-
Subscribes a callback function to be invoked on each activity update. The update callback will be invoked with the detectedActivities object.
203-
204-
##### `stop(): void`
205-
Stops listening for activity updates and remove the listener.
206-
207-
208185
## Credits / prior art
209186
210187
The following projects were very helpful in developing this library:

0 commit comments

Comments
 (0)