docs.unity3d.com
    Show / Hide Table of Contents

    Class AndroidNotificationCenter

    Use the AndroidNotificationCenter to register notification channels and schedule local notifications.

    Inheritance
    Object
    AndroidNotificationCenter
    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

    ID of the notification to cancel

    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

    ID of the notification to cancel

    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

    ID of the notification to cancel

    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

    ID of the notification to check

    Returns
    Type Description
    NotificationStatus

    The status of the notification

    DeleteNotificationChannel(String)

    Delete the specified notification channel.

    Declaration
    public static void DeleteNotificationChannel(string channelId)
    Parameters
    Type Name Description
    String channelId

    ID of the channel to delete

    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

    ID of the channel to retrieve

    Returns
    Type Description
    AndroidNotificationChannel

    Channel with given ID or empty struct if such channel does not exist

    GetNotificationChannels()

    Returns all notification channels that were created by the app.

    Declaration
    public static AndroidNotificationChannel[] GetNotificationChannels()
    Returns
    Type Description
    AndroidNotificationChannel[]

    All existing channels

    Initialize()

    Initialize the AndroidNotificationCenter class. Can be safely called multiple times

    Declaration
    public static bool Initialize()
    Returns
    Type Description
    Boolean

    True if has been successfully initialized

    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

    Channel parameters

    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

    Data for the notification

    String channelId

    ID of the channel to send notification to

    Returns
    Type Description
    Int32

    The generated ID for the notification

    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

    Data for the notification

    String channelId

    ID of the channel to send notification to

    Int32 id

    A unique ID for the notification

    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

    ID of the notification to update

    AndroidNotification notification

    Data for the notification

    String channelId

    ID of the channel to send notification to

    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
    In This Article
    • Methods
      • CancelAllDisplayedNotifications()
      • CancelAllNotifications()
      • CancelAllScheduledNotifications()
      • CancelDisplayedNotification(Int32)
      • CancelNotification(Int32)
      • CancelScheduledNotification(Int32)
      • CheckScheduledNotificationStatus(Int32)
      • DeleteNotificationChannel(String)
      • GetLastNotificationIntent()
      • GetNotificationChannel(String)
      • GetNotificationChannels()
      • Initialize()
      • RegisterNotificationChannel(AndroidNotificationChannel)
      • SendNotification(AndroidNotification, String)
      • SendNotificationWithExplicitID(AndroidNotification, String, Int32)
      • UpdateScheduledNotification(Int32, AndroidNotification, String)
    • Events
      • OnNotificationReceived
    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023