Uses activity and motion recognition to determine if the user is stationary, walking, running, or in a vehicle. More...
Import Statement: | import ArcGIS.AppFramework.Sensors 1.0 |
Properties
- error : ActivityRecognizerError
- results : ActivityRecognizerResultsModel
- state : ActivityRecognizerState
- supported : bool
- updateInterval : int
Methods
Detailed Description
The ActivityRecognition component uses device and motion sensors to detect the user's current activities. The following activities can be recognised: stationary, walking, running, biking, automotive, tilting, and unknown.
Activity recognition is only available on Android and iOS devices.
On its own, the ActivityRecognition component will only report activity updates while the app is in foreground. For an app to receive activity updates while in the background, you must include a PositionSource component in the app, and enable both location and background location in the Capabilities section of your app's Settings.
The following code snippet shows the activity recognition being refreshed every 3 seconds.
ActivityRecognizer { id: activityRecognizer updateInterval: 3000 onResultsChanged: { for (let i=1; i<results.count(); i++) { let res = results.get(i) console.log("Type " + getActivityName(res.activity)) console.log("Confidence " + getConfidenceValue(res.confidence)) console.log("Score " + res.confidenceScore) } } onStateChanged: { console.log("Activity recognition " + getStateName(state)) } onErrorChanged: { console.log(error.errorMessage) } function getActivityName(type) { switch(type) { case 0: return "Unknown" case 1: return "Stationary" case 2: return "Walking" case 3: return "Running" case 4: return "Biking" case 5: return "Automotive" case 6: return "Tilting" default: return "Unknown" } } function getConfidenceValue(confidence) { switch(confidence) { case 0: return "Low" case 1: return "Medium" case 2: return "High" } } function getStateName(state) { switch(state) { case 0: return "started" case 1: return "stopped" default: return "state unknown" } } }
Enumerations
ActivityRecognizerState enumeration
Enum describing the current state of the activity recognizer. Informs the state property.
Name | Value |
---|---|
ActivityRecognizer.ActivityRecognizerStateUnknown | -1 |
ActivityRecognizer.ActivityRecognizerStateStarted | 0 |
ActivityRecognizer.ActivityRecognizerStateStopped | 1 |
Property Documentation
[read-only] error : ActivityRecognizerError |
Describes an error encountered in activity recognition.
[read-only] results : ActivityRecognizerResultsModel |
Contains the results of the recognized activities, updated when onResultsChanged is emitted. Results include each activity type recognised and its associated confidence.
Returns the current state of the activity recognizer. Informed by the ActivityRecognizerState enum.
Returns true if activity recognition is supported by the device. Otherwise, returns false.
Provides a value in milliseconds, with 1000 representing a one second interval. The activity recognizer will update results at this interval. Be aware that sometimes it may take longer to get a more accurate prediction.