Class AndroidNotificationCenter
Use the AndroidNotificationCenter to register notification channels and schedule local notifications.
Namespace: Unity.Notifications.Android
Syntax
public class AndroidNotificationCenter
Methods
CancelAllDisplayedNotifications()
Cancel all previously shown notifications. All notifications shown by the app will be removed from the status bar. All scheduled notifications will still be shown on their scheduled time.
Declaration
public static void CancelAllDisplayedNotifications()
CancelAllNotifications()
Cancel all notifications scheduled or previously shown by the app. All scheduled notifications will be canceled. All notifications shown by the app will be removed from the status bar.
Declaration
public static void CancelAllNotifications()
CancelAllScheduledNotifications()
Cancel all notifications scheduled by the app. All scheduled notifications will be canceled. Notifications will not be removed from the status bar if they are already shown.
Declaration
public static void CancelAllScheduledNotifications()
CancelDisplayedNotification(Int32)
Cancel a previously shown notification. The notification will be removed from the status bar.
Declaration
public static void CancelDisplayedNotification(int id)
Parameters
Type | Name | Description |
---|---|---|
Int32 | id |
CancelNotification(Int32)
Cancel a scheduled or previously shown notification. The notification will no longer be displayed on it's scheduled time. If it's already delivered it will be removed from the status bar.
Declaration
public static void CancelNotification(int id)
Parameters
Type | Name | Description |
---|---|---|
Int32 | id |
CancelScheduledNotification(Int32)
Cancel a scheduled notification. The notification will no longer be displayed on it's scheduled time. It it will not be removed from the status bar if it's already delivered.
Declaration
public static void CancelScheduledNotification(int id)
Parameters
Type | Name | Description |
---|---|---|
Int32 | id |
CheckScheduledNotificationStatus(Int32)
Return the status of a scheduled notification. Only available in API 23 and above.
Declaration
public static NotificationStatus CheckScheduledNotificationStatus(int id)
Parameters
Type | Name | Description |
---|---|---|
Int32 | id |
Returns
Type | Description |
---|---|
NotificationStatus |
DeleteNotificationChannel(String)
Delete the specified notification channel.
Declaration
public static void DeleteNotificationChannel(string channelId)
Parameters
Type | Name | Description |
---|---|---|
String | channelId |
GetLastNotificationIntent()
Allows retrieving the notification used to open the app. You can save arbitrary string data in the 'AndroidNotification.IntentData' field.
Declaration
public static AndroidNotificationIntentData GetLastNotificationIntent()
Returns
Type | Description |
---|---|
AndroidNotificationIntentData | Returns the AndroidNotification used to open the app, returns null if the app was not opened with a notification. |
GetNotificationChannel(String)
Returns the notification channel with the specified id. The notification channel struct fields might not be identical to the channel struct used to initially register the channel if they were changed by the user.
Declaration
public static AndroidNotificationChannel GetNotificationChannel(string channelId)
Parameters
Type | Name | Description |
---|---|---|
String | channelId |
Returns
Type | Description |
---|---|
AndroidNotificationChannel |
GetNotificationChannels()
Returns all notification channels that were created by the app.
Declaration
public static AndroidNotificationChannel[] GetNotificationChannels()
Returns
Type | Description |
---|---|
AndroidNotificationChannel[] |
Initialize()
Initialize the AndroidNotificationCenter class.
Declaration
public static bool Initialize()
Returns
Type | Description |
---|---|
Boolean |
RegisterNotificationChannel(AndroidNotificationChannel)
Creates a notification channel that notifications can be posted to. Notification channel settings can be changed by users on devices running Android 8.0 and above. On older Android versions settings set on the notification channel struct will still be applied to the notification if they are supported to by the Android version the app is running on.
Declaration
public static void RegisterNotificationChannel(AndroidNotificationChannel channel)
Parameters
Type | Name | Description |
---|---|---|
AndroidNotificationChannel | channel |
Remarks
When a channel is deleted and recreated, all of the previous settings are restored. In order to change any settings besides the name or description an entirely new channel (with a different channel ID) must be created.
SendNotification(AndroidNotification, String)
Schedule a notification which will be shown at the time specified in the notification struct. The returned id can later be used to update the notification before it's triggered, it's current status can be tracked using CheckScheduledNotificationStatus.
Declaration
public static int SendNotification(AndroidNotification notification, string channelId)
Parameters
Type | Name | Description |
---|---|---|
AndroidNotification | notification | |
String | channelId |
Returns
Type | Description |
---|---|
Int32 |
SendNotificationWithExplicitID(AndroidNotification, String, Int32)
Schedule a notification which will be shown at the time specified in the notification struct. The specified id can later be used to update the notification before it's triggered, it's current status can be tracked using CheckScheduledNotificationStatus.
Declaration
public static void SendNotificationWithExplicitID(AndroidNotification notification, string channelId, int id)
Parameters
Type | Name | Description |
---|---|---|
AndroidNotification | notification | |
String | channelId | |
Int32 | id |
UpdateScheduledNotification(Int32, AndroidNotification, String)
Update an already scheduled notification. If a notification with the specified id was already scheduled it will be overridden with the information from the passed notification struct.
Declaration
public static void UpdateScheduledNotification(int id, AndroidNotification notification, string channelId)
Parameters
Type | Name | Description |
---|---|---|
Int32 | id | |
AndroidNotification | notification | |
String | channelId |
Events
OnNotificationReceived
Subscribe to this event to receive callbacks whenever a scheduled notification is shown to the user.
Declaration
public static event AndroidNotificationCenter.NotificationReceivedCallback OnNotificationReceived
Event Type
Type | Description |
---|---|
AndroidNotificationCenter.NotificationReceivedCallback |