wear_ongoing_activity 0.1.4 copy "wear_ongoing_activity: ^0.1.4" to clipboard
wear_ongoing_activity: ^0.1.4 copied to clipboard

Create and maintain ongoing activity notifications on Wear OS

wear_ongoing_activity #

Create and maintain ongoing activity notifications on Wear OS

Getting Started #

AndroidManifest.xml

<!-- Add permissions for the types specified in `foregroundServiceType` below -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_HEALTH" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_REMOTE_MESSAGING" />

<application>
    ...
    <service
        android:name="dev.rexios.wear_ongoing_activity.OngoingActivityService"
        android:exported="false"
        android:foregroundServiceType="health|remoteMessaging|..."
        android:stopWithTask="true" />
    ...
</application>

Make sure to request notification permission before starting an activity

import 'package:permission_handler/permission_handler.dart';

void main() {
  Permission.notification.request();
}

Usage #

Start an activity

import 'package:wear_ongoing_activity/wear_ongoing_activity.dart';

void main() {
  WearOngoingActivity.start(
    channelId: 'ongoing_activity',
    channelName: 'Ongoing Activity',
    notificationId: 12345,
    category: NotificationCategory.workout,
    smallIcon: 'ic_launcher',
    staticIcon: 'ic_launcher',
    status: OngoingActivityStatus(
      templates: [
        '#type#: #time#',
      ],
      parts: [
        TextPart(name: 'type', text: 'countup'),
        StopwatchPart(name: 'time', timeZero: DateTime.now()),
      ],
    ),
  );
}

Update an activity

import 'package:wear_ongoing_activity/wear_ongoing_activity.dart';

void main() async {
  if (!await WearOngoingActivity.isOngoing()) {
    // Attempting to update an activity that is not ongoing will throw an error
    return;
  }

  await WearOngoingActivity.update(
    OngoingActivityStatus(
      templates: [
        '#type#: #time#',
      ],
      parts: [
        TextPart(name: 'type', text: 'countdown'),
        TimerPart(
          name: 'time',
          timeZero: DateTime.now().add(const Duration(minutes: 5)),
        ),
      ],
    ),
  );
}

Stop an activity

import 'package:wear_ongoing_activity/wear_ongoing_activity.dart';

void main() {
  WearOngoingActivity.stop();
}

6
likes
0
pub points
61%
popularity

Publisher

verified publisherrexios.dev

Create and maintain ongoing activity notifications on Wear OS

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, json_annotation

More

Packages that depend on wear_ongoing_activity