-
public interface INotificationsManagerThe entry point to the notification SDK for OneSignal.
-
-
Method Summary
Modifier and Type Method Description abstract BooleanrequestPermission(Boolean fallbackToSettings)Prompt the user for permission to push notifications. abstract UnitremoveNotification(Integer id)Cancels a single OneSignal notification based on its Android notification integer ID. abstract UnitremoveGroupedNotifications(String group)Cancels a group of OneSignal notifications with the provided group key. abstract UnitclearAllNotifications()Removes all OneSignal notifications from the Notification Shade. abstract UnitaddPermissionObserver(IPermissionObserver observer)Add a permission observer that will run when the notification permission changes. abstract UnitremovePermissionObserver(IPermissionObserver observer)Remove a permission observer that has been previously added. abstract UnitaddForegroundLifecycleListener(INotificationLifecycleListener listener)Add a foreground lifecycle listener that will run whenever a notification lifecycle event occurs. abstract UnitremoveForegroundLifecycleListener(INotificationLifecycleListener listener)Remove a foreground lifecycle listener that has been previously added. abstract UnitaddClickListener(INotificationClickListener listener)Add a click listener that will run whenever a notification is clicked on by the user. abstract UnitremoveClickListener(INotificationClickListener listener)Remove a click listener that has been previously added. abstract BooleangetPermission()Whether this app has push notification permission. abstract BooleangetCanRequestPermission()Whether this app can request push notification permission. -
-
Method Detail
-
requestPermission
abstract Boolean requestPermission(Boolean fallbackToSettings)
Prompt the user for permission to push notifications. This will display the native OS prompt to request push notification permission. If the user enables, a push subscription to this device will be automatically added to the user.
Be aware of best practices regarding asking permissions on Android: Requesting Permissions | Android Developers (https://developer.android.com/guide/topics/permissions/requesting.html)
- Parameters:
fallbackToSettings- Whether to direct the user to this app's settings to drive enabling of notifications, when the in-app prompting is not possible.
-
removeNotification
abstract Unit removeNotification(Integer id)
Cancels a single OneSignal notification based on its Android notification integer ID. Use instead of Android's android.app.NotificationManager.cancel, otherwise the notification will be restored when your app is restarted.
- Parameters:
id- The android ID of the notification to be removed.
-
removeGroupedNotifications
abstract Unit removeGroupedNotifications(String group)
Cancels a group of OneSignal notifications with the provided group key. Grouping notifications is a OneSignal concept, there is no android.app.NotificationManager equivalent.
- Parameters:
group- The group key which all notifications fall under will be removed.
-
clearAllNotifications
abstract Unit clearAllNotifications()
Removes all OneSignal notifications from the Notification Shade. If you just use android.app.NotificationManager.cancelAll, OneSignal notifications will be restored when your app is restarted.
-
addPermissionObserver
abstract Unit addPermissionObserver(IPermissionObserver observer)
Add a permission observer that will run when the notification permission changes. This happens when the user enables or disables notifications for your app either within the app or from the system settings outside of your app. Disable detection is supported on Android 4.4+.
Keep a reference - Make sure to hold a reference to your handler at the class level, otherwise it may not fire.
Leak Safe - OneSignal holds a weak reference to your handler so it's guaranteed not to leak your
Activity.- Parameters:
observer- the instance of IPermissionObserver that you want to process the permission changes within
-
removePermissionObserver
abstract Unit removePermissionObserver(IPermissionObserver observer)
Remove a permission observer that has been previously added.
- Parameters:
observer- The previously added observer that should be removed.
-
addForegroundLifecycleListener
abstract Unit addForegroundLifecycleListener(INotificationLifecycleListener listener)
Add a foreground lifecycle listener that will run whenever a notification lifecycle event occurs.
- Parameters:
listener- : The listener that is to be called when the event occurs.
-
removeForegroundLifecycleListener
abstract Unit removeForegroundLifecycleListener(INotificationLifecycleListener listener)
Remove a foreground lifecycle listener that has been previously added.
- Parameters:
listener- The previously added listener that should be removed.
-
addClickListener
abstract Unit addClickListener(INotificationClickListener listener)
Add a click listener that will run whenever a notification is clicked on by the user.
- Parameters:
listener- The listener that is to be called when the event occurs.
-
removeClickListener
abstract Unit removeClickListener(INotificationClickListener listener)
Remove a click listener that has been previously added.
- Parameters:
listener- The previously added listener that should be removed.
-
getPermission
abstract Boolean getPermission()
Whether this app has push notification permission.
-
getCanRequestPermission
abstract Boolean getCanRequestPermission()
Whether this app can request push notification permission.
-
-
-
-