GithubHelp home page GithubHelp logo

danielmartini / wear_ongoing_activity Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rexios80/wear_ongoing_activity

0.0 0.0 0.0 83 KB

Create and maintain ongoing activity notifications on Wear OS

Home Page: https://pub.dev/packages/wear_ongoing_activity

License: BSD 3-Clause "New" or "Revised" License

Kotlin 36.96% Dart 63.04%

wear_ongoing_activity's Introduction

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,
    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();
}

wear_ongoing_activity's People

Contributors

rexios80 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.