wear_ongoing_activity 0.1.0 copy "wear_ongoing_activity: ^0.1.0" to clipboard
wear_ongoing_activity: ^0.1.0 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

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<!-- 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() async {
  await 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,
    foregroundServiceTypes: {
      ForegroundServiceType.health,
      ForegroundServiceType.remoteMessaging,
    },
    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() {
  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