wear_ongoing_activity 0.1.3+1 wear_ongoing_activity: ^0.1.3+1 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() 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,
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();
}