npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@capawesome-team/capacitor-android-foreground-service

v8.1.0

Published

Capacitor plugin to run a foreground service on Android.

Readme

@capawesome-team/capacitor-android-foreground-service

Capacitor plugin to run a foreground service on Android.

Newsletter

Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our Capawesome Newsletter.

Compatibility

| Plugin Version | Capacitor Version | Status | | -------------- | ----------------- | -------------- | | 8.x.x | >=8.x.x | Active support |

Installation

You can use our AI-Assisted Setup to install the plugin. Add the Capawesome Skills to your AI tool using the following command:

npx skills add capawesome-team/skills

Then use the following prompt:

Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome-team/capacitor-android-foreground-service` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capawesome-team/capacitor-android-foreground-service
npx cap sync

Android

This API requires the following permissions be added to your AndroidManifest.xml before or after the application tag:

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
<!-- Required to keep the app running in the background without any ressource limitations -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- Required to request the manage overlay permission -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

Attention: Replace FOREGROUND_SERVICE_LOCATION with the foreground service types you want to use (see Foreground service types). See ServiceType for the available types.

You also need to add the following receiver and service inside the application tag in your AndroidManifest.xml:

<receiver android:name="io.capawesome.capacitorjs.plugins.foregroundservice.NotificationActionBroadcastReceiver" />
<service android:name="io.capawesome.capacitorjs.plugins.foregroundservice.AndroidForegroundService" android:foregroundServiceType="location" />

Attention: Replace location with the foreground service types you want to use (see Foreground service types). See ServiceType for the available types.

Configuration

No configuration required for this plugin.

Demo

A working example can be found here: robingenz/capacitor-plugin-demo

| Android | | -------------------------------------------------------------------------------------------------------------------------------------------------- | | |

Usage

import { Capacitor } from '@capacitor/core';
import { ForegroundService } from '@capawesome-team/capacitor-android-foreground-service';

const startForegroundService = async () => {
  await ForegroundService.startForegroundService({
    id: 1,
    title: 'Title',
    body: 'Body',
    smallIcon: 'ic_stat_icon_config_sample',
    buttons: [
      {
        title: 'Button 1',
        id: 1,
      },
      {
        title: 'Button 2',
        id: 2,
      },
    ],
    silent: false,
    notificationChannelId: 'default',
  });
};

const updateForegroundService = async () => {
  await ForegroundService.updateForegroundService({
    id: 1,
    title: 'Title',
    body: 'Body',
    smallIcon: 'ic_stat_icon_config_sample',
  });
};

const stopForegroundService = async () => {
  await ForegroundService.stopForegroundService();
};

const createNotificationChannel = async () => {
  await ForegroundService.createNotificationChannel({
    id: 'default',
    name: 'Default',
    description: 'Default channel',
    importance: Importance.Default,
  });
};

const deleteNotificationChannel = async () => {
  await ForegroundService.deleteNotificationChannel({
    id: 'default',
  });
};

API

moveToForeground()

moveToForeground() => Promise<void>

Moves the app to the foreground.

On Android SDK 23+, the user must grant the manage overlay permission. You can use the requestManageOverlayPermission() method to request the permission and the checkManageOverlayPermission() method to check if the permission is granted.

Only available on Android.

Since: 0.3.0


startForegroundService(...)

startForegroundService(options: StartForegroundServiceOptions) => Promise<void>

Starts the foreground service.

Only available on Android.

| Param | Type | | ------------- | --------------------------------------------------------------------------------------- | | options | StartForegroundServiceOptions |

Since: 0.0.1


updateForegroundService(...)

updateForegroundService(options: UpdateForegroundServiceOptions) => Promise<void>

Updates the notification details of the running foreground service.

Only available on Android.

| Param | Type | | ------------- | --------------------------------------------------------------------------------------- | | options | StartForegroundServiceOptions |

Since: 6.1.0


stopForegroundService()

stopForegroundService() => Promise<void>

Stops the foreground service.

Only available on Android.

Since: 0.0.1


checkPermissions()

checkPermissions() => Promise<PermissionStatus>

Check permission to display notifications.

On Android, this method only needs to be called on Android 13+.

Only available on Android.

Returns: Promise<PermissionStatus>

Since: 5.0.0


requestPermissions()

requestPermissions() => Promise<PermissionStatus>

Request permission to display notifications.

On Android, this method only needs to be called on Android 13+.

Only available on Android.

Returns: Promise<PermissionStatus>

Since: 5.0.0


checkManageOverlayPermission()

checkManageOverlayPermission() => Promise<ManageOverlayPermissionResult>

Check if the overlay permission is granted.

Only available on Android.

Returns: Promise<ManageOverlayPermissionResult>

Since: 0.3.0


requestManageOverlayPermission()

requestManageOverlayPermission() => Promise<ManageOverlayPermissionResult>

Request the manage overlay permission.

Only available on Android.

Returns: Promise<ManageOverlayPermissionResult>

Since: 0.3.0


createNotificationChannel(...)

createNotificationChannel(options: CreateNotificationChannelOptions) => Promise<void>

Create a notification channel. If not invoked, the plugin creates a channel with name and description set to "Default".

Only available for Android (SDK 26+).

| Param | Type | | ------------- | --------------------------------------------------------------------------------------------- | | options | CreateNotificationChannelOptions |

Since: 6.1.0


deleteNotificationChannel(...)

deleteNotificationChannel(options: DeleteNotificationChannelOptions) => Promise<void>

Delete a notification channel.

Only available for Android (SDK 26+).

| Param | Type | | ------------- | --------------------------------------------------------------------------------------------- | | options | DeleteNotificationChannelOptions |

Since: 6.1.0


addListener('buttonClicked', ...)

addListener(eventName: 'buttonClicked', listenerFunc: ButtonClickedEventListener) => Promise<PluginListenerHandle>

Called when a notification button is clicked.

Only available on iOS.

| Param | Type | | ------------------ | --------------------------------------------------------------------------------- | | eventName | 'buttonClicked' | | listenerFunc | ButtonClickedEventListener |

Returns: Promise<PluginListenerHandle>

Since: 0.2.0


addListener('notificationTapped', ...)

addListener(eventName: 'notificationTapped', listenerFunc: NotificationTappedEventListener) => Promise<PluginListenerHandle>

Called when the foreground service notification is tapped.

Only available on Android.

| Param | Type | | ------------------ | ------------------------------------------------------------------------------------------- | | eventName | 'notificationTapped' | | listenerFunc | NotificationTappedEventListener |

Returns: Promise<PluginListenerHandle>

Since: 8.1.0


removeAllListeners()

removeAllListeners() => Promise<void>

Remove all listeners for this plugin.

Since: 0.2.0


Interfaces

StartForegroundServiceOptions

| Prop | Type | Description | Default | Since | | --------------------------- | --------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- | | body | string | The body of the notification, shown below the title. | | 0.0.1 | | buttons | NotificationButton[] | The buttons to show on the notification. Only available on Android (SDK 24+). | | 0.2.0 | | id | number | The notification identifier. | | 0.0.1 | | serviceType | ServiceType | The foreground service type. Only available on Android (SDK 29+). | | 6.2.0 | | smallIcon | string | The status bar icon for the notification. Icons should be placed in your app's res/drawable folder. The value for this option should be the drawable resource ID, which is the filename without an extension. | | 0.0.1 | | title | string | The title of the notification. | | 0.0.1 | | silent | boolean | If true, will only alert (sound/vibration) on the first notification. Subsequent updates will be silent. | false | 6.1.0 | | notificationChannelId | string | The notification channel identifier. | | 6.1.0 |

NotificationButton

| Prop | Type | Description | Since | | ----------- | ------------------- | ----------------------------------------------------------------------------------------------------- | ----- | | title | string | The button title. | 0.2.0 | | id | number | The button identifier. This is used to identify the button when the buttonClicked event is emitted. | 0.2.0 |

PermissionStatus

| Prop | Type | Description | Since | | ------------- | ----------------------------------------------------------- | --------------------------------------------- | ----- | | display | PermissionState | Permission state of displaying notifications. | 5.0.0 |

ManageOverlayPermissionResult

| Prop | Type | Description | Since | | ------------- | -------------------- | -------------------------------------------------------------------------------- | ----- | | granted | boolean | Whether the permission is granted. This is always true on Android SDK < 23. | 0.3.0 |

CreateNotificationChannelOptions

| Prop | Type | Description | Since | | ----------------- | ------------------------------------------------- | ------------------------------------------------------------------- | ----- | | description | string | The description of this channel (presented to the user). | 6.1.0 | | id | string | The channel identifier. | 6.1.0 | | importance | Importance | The level of interruption for notifications posted to this channel. | 6.1.0 | | name | string | The name of this channel (presented to the user). | 6.1.0 |

DeleteNotificationChannelOptions

| Prop | Type | Description | Since | | -------- | ------------------- | ----------------------- | ----- | | id | string | The channel identifier. | 6.1.0 |

PluginListenerHandle

| Prop | Type | | ------------ | ----------------------------------------- | | remove | () => Promise<void> |

ButtonClickedEvent

| Prop | Type | Description | Since | | -------------- | ------------------- | ---------------------- | ----- | | buttonId | number | The button identifier. | 0.2.0 |

NotificationTappedEvent

| Prop | Type | Description | Since | | -------------------- | ------------------- | ---------------------------- | ----- | | notificationId | number | The notification identifier. | 8.1.0 |

Type Aliases

UpdateForegroundServiceOptions

StartForegroundServiceOptions

PermissionState

'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'

ButtonClickedEventListener

(event: ButtonClickedEvent): void

NotificationTappedEventListener

(event: NotificationTappedEvent): void

Enums

ServiceType

| Members | Value | Description | Since | | ---------------- | ---------------- | ----------------------------------------------------------------------------------------------- | ----- | | Location | 8 | Long-running use cases that require location access, such as navigation and location sharing. | 6.2.0 | | Microphone | 128 | Continue microphone capture from the background, such as voice recorders or communication apps. | 6.2.0 |

Importance

| Members | Value | Since | | ------------- | -------------- | ----- | | Min | 1 | 6.1.0 | | Low | 2 | 6.1.0 | | Default | 3 | 6.1.0 | | High | 4 | 6.1.0 | | Max | 5 | 6.1.0 |

FAQ

Why can the user dismiss the notification?

Android 14 has changed the behavior to allow users to dismiss such notifications, see Changes to how users experience non-dismissible notifications.

Changelog

See CHANGELOG.md.

License

See LICENSE.