0.0.1 • Published 1 year ago

@techrover_solutions/capacitor-fullscreen-notification v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

A fork from https://www.npmjs.com/package/capacitor-fullscreen-notification With custom features for Techrover Solutions internal use

Author: Deval99

npm version capacitor support

capacitor-fullscreen-notification

This plugin can automatically launch your app, triggered by a data push notification by the @capacitor/push-notifications plugin.

Use case example: Someone rings your doorbell -> your app opens and navigates to a specific route

Supported platforms

PlatformSupported
Android
iOS
Web

Install

npm install capacitor-fullscreen-notification
npx cap sync android

Add this to the activity inside your AndroidManifest.xml:

android:showWhenLocked="true"
android:turnScreenOn="true"

Android behavior

The Android OS differs between an locked and unlocked device.

Locked

The app will only be launched instantly, when your device is in standby.

Unlocked

If your device is not in standby, you will get a default heads up notification with the defined title, text and actionButtons. When you click on it, the app will launch.

HINT
To identify if the app has been launched instantly or by clicking the heads up notification, you can check the property 'isNotificationActive' in the response data of your 'launch' listener. This is true on instant launch.

Workflow

This plugin will start a fullscreen intent by a local notification, when it receives a specific data push notification.

Firebase
1. Send a data push
Plugin
2. Receives the data push
3. Sends a local notification with full screen intent (opens app)
4. Emits a plugin event
App
5. Listen to event and redirect to any page

Usage

Trigger push

Send a data push notification (leave the field notification empty!) with the following key value pairs in the data option:

OptionDescription
fullScreenId(Required) Identifier of the fullscreen notification
channelIdIdentifier of the notification channel
channelNameName of the notification channel
channelDescriptionDescription of the notification channel
titleTitle of the heads up notification
textText of the heads up notification
timeoutTimeout, for auto removing the notification
vibrationPatternStringified array of long values (docs)
actionButtonsStringified array of ActionButton objects

ActionButton

PropDescription
idIdentifier of the button
textButton text

Example

{
  "fullScreenId": "my-fullscreen-identifier",
  "channelId": "fullscreen-channel",
  "channelName": "My Fullscreen Channel",
  "channelDescription": "Notifications in this channel will be displayed with a fullscreen intent",
  "title": "Test notification",
  "text": "Test description",
  "timeout": "10000",
  "vibrationPattern": "[500, 300, 500, 300, 500, 300, 500, 300]",
  "actionButtons": "[{ \"id\": \"reject\", \"text\": \"Reject\" }, { \"id\": \"accept\", \"text\": \"Accept\" }]"
}

App

In your app, you can listen to the launch of the application. This event is fired when the fullscreen notification opens or the heads up notification is clicked. You can also cancel the active notification, if it exists:

import { FullScreenNotification } from 'capacitor-fullscreen-notification';

FullScreenNotification.addListener('launch', (data) => {
    ...
});

...

await FullScreenNotification.cancelNotification();

Inside the data of the launch event, you can have the following data:

PropTypeDescription
fullScreenIdstringIdentifier of the triggering request
isNotificationActivebooleanIs the notification still active
timeoutnumber(Optionally) Timeout value of the triggering request
actionIdstring(Optionally) Idenfifier of the clicked action button

API

cancelNotification()

cancelNotification() => Promise<void>

Cancel the current notification


addListener('launch', ...)

addListener(eventName: 'launch', listenerFunc: MessageListener) => Promise<PluginListenerHandle> & PluginListenerHandle

Add a listener when the fullscreen intent launches the app. You can navigate here to the destination page. The parameter gives you the information if an action button has been clicked.

ParamType
eventName'launch'
listenerFuncMessageListener

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


removeAllListeners()

removeAllListeners() => Promise<void>

Removes all listeners.


Interfaces

PluginListenerHandle

PropType
remove() => Promise<void>

Type Aliases

MessageListener

(response: any): void

0.0.1

1 year ago