docs.unity.cn
Search Results for

    Show / Hide Table of Contents

    Class AndroidNotificationCenter

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

    Inheritance
    object
    AndroidNotificationCenter
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    Namespace: Unity.Notifications.Android
    Assembly: solution.dll
    Syntax
    public class AndroidNotificationCenter

    Fields

    Name Description
    SETTING_POST_NOTIFICATIONS_PERMISSION

    A PlayerPrefs key used to save users reply to POST_NOTIFICATIONS request (integer value of the PermissionStatus). Value is one of PermissionStatus

    Properties

    Name Description
    IgnoringBatteryOptimizations

    Whether app is ignoring device battery optimization settings. When device is in power saving or similar restricted mode, scheduled notifications may not appear or be late.

    ShouldShowPermissionToPostRationale

    Returns true if app should show UI explaining why it need permission to post notifications. The UI should be shown before requesting the permission.

    UserPermissionToPost

    Has user given permission to post notifications. Before Android 13 (API 33) no permission is required, but user can disable notifications in the Settings since Android 7 (API 24).

    UsingExactScheduling

    Whether notifications are scheduled at exact times. Combines notification settings and actual device settings (since Android 12 exact scheduling is user controllable).

    Methods

    Name Description
    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.

    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.

    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.

    CancelDisplayedNotification(int)

    Cancel a previously shown notification. The notification will be removed from the status bar.

    CancelNotification(int)

    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.

    CancelScheduledNotification(int)

    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.

    CheckScheduledNotificationStatus(int)

    Return the status of a scheduled notification.

    CreateNotificationBuilder(int, AndroidNotification, string)

    Create Notification.Builder object on Java side using privided AndroidNotification.

    CreateNotificationBuilder(AndroidNotification, string)

    Create Notification.Builder. Will automatically generate the ID for notification. CreateNotificationBuilder(int, AndroidNotification, string)

    DeleteNotificationChannel(string)

    Delete the specified notification channel.

    DeleteNotificationChannelGroup(string)

    Delete notification channel group and all the channels in it.

    GetLastNotificationIntent()

    Allows retrieving the notification used to open the app. You can save arbitrary string data in the 'AndroidNotification.IntentData' field.

    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.

    GetNotificationChannels()

    Returns all notification channels that were created by the app.

    Initialize()

    Initialize the AndroidNotificationCenter class. Can be safely called multiple times

    OpenNotificationSettings(string)

    Opens settings. On Android versions lower than 8.0 opens settings for the application. On Android 8.0 and later opens notification settings for the specified channel, or for the application, if channelId is null. Note, that opening settings will suspend the application and switch to settings app.

    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.

    RegisterNotificationChannelGroup(AndroidNotificationChannelGroup)

    Register notification channel group.

    RequestExactScheduling()

    Request user permission to schedule alarms at exact times. Only works on Android 12 and later, older versions can schedule at exact times without requesting it. This may cause your app to use more battery. App must have SCHEDULE_EXACT_ALARM permission to be able to request this.

    RequestIgnoreBatteryOptimizations()

    Request user to allow unrestricted background work for app. UI for it is provided by OS and is manufacturer specific. Recommended to explain user what to do before requesting. App must have REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission to be able to request this.

    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.

    SendNotification(AndroidJavaObject)

    Schedule a notification created using the provided Notification.Builder object. Notification builder should be created by calling CreateNotificationBuilder.

    SendNotification(AndroidJavaObject, out int)

    Schedule a notification created using the provided Notification.Builder object. Notification builder should be created by calling CreateNotificationBuilder. Stores the notification id to the second argument

    SendNotificationWithExplicitID(AndroidNotification, string, int)

    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.

    UpdateScheduledNotification(int, 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.

    Events

    Name Description
    OnNotificationReceived

    Subscribe to this event to receive callbacks whenever a scheduled notification is shown to the user.

    In This Article
    Back to top
    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