Skip to content

OneSignal Notifications

Non-Visible component
Category Requires Version
Social API 21, Android 5.0 Lollipop 1

Overview

A non-visible component for receiving and controlling push notifications sent remotely using OneSignal.

Permissions

Events

Error Occurred

Called when an error occurs.

Params
message Text

Notification Clicked

Called when the user clicks the notification.

Params
android Notification ID Number
from Project Number Text
group Key Text
sent Time Number
ttl Number
notification ID Text

Notification Permission State Changed

Called when the user accepts or declines the permission prompt, or enables or disables notifications for your app in the device's app settings and then returns to your app.

Params
granted Boolean

Push Subscription State Changed

Called when subscription state changes. This can happen when: 1. The device receives a new push token from Google (FCM) or Apple (APNs). 2. OneSignal assigns a subscription ID. 3. The optedIn value changes (e.g. called "OptIn" or "OptOut"). 4. The user toggles push permission in system settings, then opens the app.

Params
subscription Id Text
opted In Boolean
token Text

Methods

Get Push Subscription ID

Returns: Text

Returns the current push subscription ID. May return null if called too early.

Get Push Subscription Token

Returns: Text

Returns the current push subscription token. May return null if called too early.

Has Opted In

Returns: Boolean

Returns true if the current push subscription status is subscribed, otherwise false. If the push token is valid but OptOut was called, this will return false.

Opt In

Does one of three actions: 1. If the Subscription has a valid push token, it sets the current push subscription status to subscribed. 2. If the Subscription does not have a valid push token, it displays the push permission prompt. 3. If the push permission prompt has been displayed more than the operating system's limit (twice Android), it displays the fallback prompt.

Opt Out

Sets the current push subscription status to unsubscribed (even if the user has a valid push token).

Remove All Notifications

Removes all OneSignal notifications.

Remove Grouped Notifications

Cancel all notifications in a specific group based on its group key.

Params
group Key Text

Remove Notification

Cancel a single notification based on its Android notification ID.

Params
android Notification ID Number

Request Notification Permission

Shows the native system prompt asking the user for push notification permission. If "fallbackToSettings" is true, the fallback prompt will be displayed if the user denied push permissions more than twice.

Params
fallback To Settings Boolean

Properties

Can Request Permission

Continuation ➖ Write - Blocks

Returns whether attempting to request permission will result in a prompt being displayed to the user. If false, the user has already denied permission and can either be shown the fallback prompt or no prompt at all.