Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/activity_recognition_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
## 6.0.0

Breaking changes:

- Requires Flutter 3.44 and Dart 3.10
- Android package has been renamed to `dk.carp.activity_recognition_flutter`.
- Apps that referenced the old package in their manifest or ProGuard rules need to update those references
- `ActivityEvent` now takes the timestamp (optional)
- Minimum iOS deployment target is 15.0 and the Android `compileSdk` is 36
- CocoaPods is no longer supported on iOS
- Added Swift Package Manager (SPM)
- Moved Android impls to Kotlin
- Plugin now declares its own permissions, broadcast receiver and foreground
service in its manifest
- Removed `ActivityRecognizedService`
- Removed `ActivityType.INVALID`
- Removed `ActivityEvent.fromString`
- Fixed activity timestamps source to the platform's `CMMotionActivity.startDate` on
iOS, `ActivityRecognitionResult.time` on Android
- Fixed Android events deregister on stream cancel

## 5.0.0

- upgraded Android SDK level
Expand Down
52 changes: 31 additions & 21 deletions packages/activity_recognition_flutter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,28 @@

Activity recognition plugin for Android and iOS. Only working while App is running (= not terminated by the user or OS).

The communication with the native platforms is defined in [`pigeons/messages.dart`](pigeons/messages.dart)
and generated with [Pigeon](https://pub.dev/packages/pigeon). Regenerate it after
changing that file with:

## Configuration
```sh
dart run pigeon --input pigeons/messages.dart
```

### Android
The iOS implementation is a Swift package (`ios/activity_recognition_flutter/`).
CocoaPods is no longer supported, so consuming apps must use Swift Package
Manager. See [iOS](#ios) below.

Add the following entries inside the `<manifest>` tag:

```xml
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
```
## Configuration

Next, add the plugin's service inside the `<application>` tag:
### Android

```xml
<receiver android:name="dk.cachet.activity_recognition_flutter.ActivityRecognizedBroadcastReceiver"/>
<service
android:name="dk.cachet.activity_recognition_flutter.ActivityRecognizedService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="true"/>
<service android:name="dk.cachet.activity_recognition_flutter.ForegroundService" />
```
The permissions the plugin requires, and the broadcast receiver and
foreground service it relies on, are declared by the plugin.

You still have to request the `ACTIVITY_RECOGNITION` runtime permission before
listening to the stream -- see [Usage](#usage) below.

#### Known Android quirks

Expand All @@ -37,7 +36,19 @@ This package uses the Android Embedding API v2. In order to use this in pre-Flut

### iOS

An iOS app linked on or after iOS 10.0 must include usage description keys in its `Info.plist` file for the types of data it needs. Failure to include these keys will cause the app to crash.
This plugin ships only as a Swift package, so your app must use Swift Package
Manager. It is enabled by default on Flutter 3.44 and later; if you turned it
off, re-enable it with:

```sh
flutter config --enable-swift-package-manager
```

If your app still has CocoaPods integration, see
[Flutter Swift Package Manager guide](https://docs.flutter.dev/packages-and-plugins/swift-package-manager/for-app-developers)
for details.

An iOS app linked on must include usage description keys in its `Info.plist` file for the types of data it needs. Failure to include these keys will cause the app to crash.
To access motion and fitness data specifically, it must include `NSMotionUsageDescription`, like this:

```xml
Expand All @@ -63,7 +74,6 @@ Each detected activity will have an activity type, which is one of the following
* TILTING
* UNKNOWN
* WALKING
* INVALID (used for parsing errors)

As well as a confidence expressed in percentages (i.e. a value from 0-100).

As well as a confidence expressed in percentages (i.e. a value from 0-100), and
the timestamp of the detection as reported by the platform.
38 changes: 0 additions & 38 deletions packages/activity_recognition_flutter/android/build.gradle

This file was deleted.

63 changes: 63 additions & 0 deletions packages/activity_recognition_flutter/android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
group = "dk.carp.activity_recognition_flutter"
version = "1.0"

allprojects {
repositories {
google()
mavenCentral()
}
}

plugins {
id("com.android.library")
}

// AGP 9+ has built-in Kotlin support; on older AGP the Kotlin Gradle plugin
// must be applied explicitly. Version is supplied by the consuming app.
// See https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors
val agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.substringBefore('.').toInt()
if (agpMajor < 9) {
apply(plugin = "org.jetbrains.kotlin.android")
}

android {
namespace = "dk.carp.activity_recognition_flutter"

// Kept at the lowest currently supported level on purpose: a library forces
// every app that depends on it to compile against at least this SDK.
compileSdk = 36

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

sourceSets {
getByName("main") {
java.srcDirs("src/main/kotlin")
}
}

defaultConfig {
// API 26 is required by the plugin itself: notification channels and
// Context.startForegroundService were both added in Android 8.
minSdk = 26
}

lint {
disable += "InvalidPackage"
}
}

// Configured reflectively rather than through the `kotlin { }` accessor: the
// Kotlin plugin is applied after this script is compiled (by Flutter, or
// conditionally above), so the type-safe accessor does not exist here.
project.extensions.configure(org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension::class.java) {
compilerOptions {
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
}
}

dependencies {
implementation("com.google.android.gms:play-services-location:21.3.0")
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = "activity_recognition_flutter"
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dk.cachet.activity_recognition_flutter">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

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

<!-- Declared here so that apps using the plugin do not have to repeat them. -->
<application>
<receiver
android:name=".ActivityRecognizedBroadcastReceiver"
android:exported="false" />

<service
android:name=".ForegroundService"
android:exported="false"
android:foregroundServiceType="health" />
</application>

</manifest>
Loading
Loading