flutter_activity_recognition 1.3.0 icon indicating copy to clipboard operation
flutter_activity_recognition: ^1.3.0 copied to clipboard

This plugin is used to recognize user activity on Android and iOS platforms.

This plugin is used to recognize user activity on Android and iOS platforms. To implement this plugin, Android used ActivityRecognitionClient and iOS used CMMotionActivityManager.

pub package

Features #

  • Can check or request activity recognition permission.
  • Subscribe to an activity stream to detect user activity in real time.

Getting started #

To use this plugin, add flutter_activity_recognition as a dependency in your pubspec.yaml file. For example:

  flutter_activity_recognition: ^1.3.0

After adding the flutter_activity_recognition plugin to the flutter project, we need to specify the platform-specific permissions and services to use for this plugin to work properly.

🐤 Android #

Open the AndroidManifest.xml file and add the following permissions between the <manifest> and <application> tags.

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />

🐤 iOS #

Open the ios/Runner/Info.plist file and add the following permission inside the <dict> tag.

<string>Used to recognize user activity information.</string>

How to use #

  1. Create a FlutterActivityRecognition instance.
final activityRecognition = FlutterActivityRecognition.instance;
  1. Checks whether activity recognition permission is granted.
Future<bool> isPermissionGrants() async {
  // Check if the user has granted permission. If not, request permission.
  PermissionRequestResult reqResult;
  reqResult = await activityRecognition.checkPermission();
  if (reqResult == PermissionRequestResult.PERMANENTLY_DENIED) {
    dev.log('Permission is permanently denied.');
    return false;
  } else if (reqResult == PermissionRequestResult.DENIED) {
    reqResult = await activityRecognition.requestPermission();
    if (reqResult != PermissionRequestResult.GRANTED) {
      dev.log('Permission is denied.');
      return false;

  return true;
  1. Subscribe to an activity stream to receive activity data in real time.
// Subscribe to the activity stream.
final _activityStreamSubscription = activityRecognition.activityStream
  1. When the widget is dispose or the plugin is finished using, cancel the subscription.
void dispose() {

Models #

🐔 PermissionRequestResult #

Defines the type of permission request result.

GRANTEDOccurs when the user grants permission.
DENIEDOccurs when the user denies permission.
PERMANENTLY_DENIEDOccurs when the user denies the permission once and chooses not to ask again.

🐔 Activity #

A model representing the user's activity.

typeThe type of activity recognized.
confidenceThe confidence of activity recognized.

🐔 ActivityType #

Defines the type of activity.

IN_VEHICLEThe device is in a vehicle, such as a car.
ON_BICYCLEThe device is on a bicycle.
RUNNINGThe device is on a user who is running. This is a sub-activity of ON_FOOT.
STILLThe device is still (not moving).
WALKINGThe device is on a user who is walking. This is a sub-activity of ON_FOOT.
UNKNOWNUnable to detect the current activity.

🐔 ActivityConfidence #

Defines the confidence of activity.

HIGHHigh accuracy: 80~100
MEDIUMMedium accuracy: 50~80
LOWLow accuracy: 0~50

Support #

If you find any bugs or issues while using the plugin, please register an issues on GitHub. You can also contact us at hwj930513@naver.com.

pub points


unverified uploader

This plugin is used to recognize user activity on Android and iOS platforms.



API reference


Icon for licenses.MIT (LICENSE)




Packages that depend on flutter_activity_recognition