capacitor-timer-notification
v0.2.4
Published
timer notifcation
Readme
capacitor-timer-notification
A Capacitor plugin to create a timer notification that displays a countdown timer in the notification bar.
Usage
Please provide an audio file in the android/app/src/main/res/raw directory of your project. The plugin will use this audio file to play a sound when the timer is up.
Add the following to your android/app/src/main/AndroidManifest.xml file to declare the necessary permissions and service:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<service
android:name=".TimerService"
android:enabled="true"
android:exported="false"
android:foregroundServiceType="mediaPlayback"/>
## Install
```bash
npm install capacitor-timer-notification
npx cap syncAPI
startTimer(...)stopTimer()pauseTimer()resumeTimer()addListener('remainingTimeUpdate', ...)removeAllListeners(...)- Interfaces
startTimer(...)
startTimer(options: { duration: number; }) => Promise<void>Starts the timer with the given duration in seconds.
| Param | Type | Description |
| ------------- | ---------------------------------- | ---------------------------------------------- |
| options | { duration: number; } | - Object containing the duration of the timer. |
stopTimer()
stopTimer() => Promise<void>Stops the currently running timer.
pauseTimer()
pauseTimer() => Promise<void>Pauses the currently running timer.
resumeTimer()
resumeTimer() => Promise<void>Resumes the paused timer.
addListener('remainingTimeUpdate', ...)
addListener(eventName: 'remainingTimeUpdate', listenerFunc: (data: { remainingTime: number; }) => void) => Promise<PluginListenerHandle>Listens for updates on the remaining time of the timer.
| Param | Type | Description |
| ------------------ | ---------------------------------------------------------- | ----------------------------------------------------- |
| eventName | 'remainingTimeUpdate' | - The name of the event, e.g., "remainingTimeUpdate". |
| listenerFunc | (data: { remainingTime: number; }) => void | - Callback function that receives the remaining time. |
Returns: Promise<PluginListenerHandle>
removeAllListeners(...)
removeAllListeners(eventName: string) => Promise<void>Removes all listeners for a given event.
| Param | Type | Description |
| --------------- | ------------------- | ------------------------------------------------ |
| eventName | string | - The name of the event to remove listeners for. |
Interfaces
PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| remove | () => Promise<void> |
