#if UNITY_ANDROID using UnityEngine; namespace NotificationSamples.Android { /// /// Class for managing Android notification center extensions. /// public class AndroidNotificationCenterExtensions { private static bool s_Initialized; private static AndroidJavaObject s_AndroidNotificationExtensions; /// /// Initialize the Android notification center extensions. /// public static bool Initialize() { if (s_Initialized) { return true; } #if UNITY_EDITOR s_AndroidNotificationExtensions = null; s_Initialized = false; #else AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject activity = unityPlayer.GetStatic("currentActivity"); AndroidJavaObject context = activity.Call("getApplicationContext"); AndroidJavaClass managerClass = new AndroidJavaClass("com.unity.androidnotifications.UnityNotificationManager"); AndroidJavaObject notificationManagerImpl = managerClass.CallStatic("getNotificationManagerImpl", context, activity); AndroidJavaObject notificationManager = notificationManagerImpl.Call("getNotificationManager"); AndroidJavaClass pluginClass = new AndroidJavaClass("com.unity.androidnotifications.AndroidNotificationCenterExtensions"); s_AndroidNotificationExtensions = pluginClass.CallStatic("getExtensionsImpl", context, notificationManager); s_Initialized = true; #endif return s_Initialized; } /// /// Checks whether notifications are enabled on any channel. /// public static bool AreNotificationsEnabled() { if (!s_Initialized) { // By default notifications are enabled return true; } return s_AndroidNotificationExtensions.Call("areNotificationsEnabled"); } /// /// Checks whether notifications are enabled on a specific channel. /// /// The ID of the channel. public static bool AreNotificationsEnabled(string channelId) { if (!s_Initialized) { // By default notifications are enabled return true; } return s_AndroidNotificationExtensions.Call("areNotificationsEnabled", channelId); } } } #endif