Example #1
0
        public static bool Initialize()
        {
            if (initialized)
            {
                return(true);
            }

            if (AndroidReceivedNotificationMainThreadDispatcher.GetInstance() == null)
            {
                var receivedNotificationDispatcher = new GameObject("AndroidReceivedNotificationMainThreadDispatcher");
                receivedNotificationDispatcher.AddComponent <AndroidReceivedNotificationMainThreadDispatcher>();
            }

            #if UNITY_EDITOR || !UNITY_ANDROID
            return(false);
            #endif

            AndroidJavaClass  unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject activity    = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity");
            AndroidJavaObject context     = activity.Call <AndroidJavaObject>("getApplicationContext");

            AndroidJavaClass managerClass =
                new AndroidJavaClass("com.unity.androidnotifications.UnityNotificationManager");

            notificationManager =
                managerClass.CallStatic <AndroidJavaObject>("getNotificationManagerImpl", context, activity);
            notificationManager.Call("setNotificationCallback", new NotificationCallback());

            AndroidJavaClass buildVersion = new AndroidJavaClass("android.os.Build$VERSION");
            AndroidSDK = buildVersion.GetStatic <int>("SDK_INT");

            return(initialized = true);
        }
Example #2
0
        /// <summary>
        /// Initialize the AndroidNotificationCenter class.
        /// Can be safely called multiple times
        /// </summary>
        /// <returns>True if has been successfully initialized</returns>
        public static bool Initialize()
        {
            if (s_Initialized)
            {
                return(true);
            }

            if (AndroidReceivedNotificationMainThreadDispatcher.GetInstance() == null)
            {
                var receivedNotificationDispatcher = new GameObject("AndroidReceivedNotificationMainThreadDispatcher");
                receivedNotificationDispatcher.AddComponent <AndroidReceivedNotificationMainThreadDispatcher>();
            }

#if UNITY_EDITOR || !UNITY_ANDROID
            s_CurrentActivity = null;
#elif UNITY_ANDROID
            var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            s_CurrentActivity = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity");
            var context = s_CurrentActivity.Call <AndroidJavaObject>("getApplicationContext");

            var notificationManagerClass = new AndroidJavaClass("com.unity.androidnotifications.UnityNotificationManager");
            var notificationManager      = notificationManagerClass.CallStatic <AndroidJavaObject>("getNotificationManagerImpl", context, s_CurrentActivity);
            notificationManager.Call("setNotificationCallback", new NotificationCallback());
            s_Jni = new JniApi(notificationManagerClass, notificationManager);

            s_Initialized = true;
#endif
            return(s_Initialized);
        }
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
         DontDestroyOnLoad(this.gameObject);
     }
 }
 void OnDestroy()
 {
     instance = null;
 }
Example #5
0
 public void onSentNotification(AndroidJavaObject notification)
 {
     AndroidReceivedNotificationMainThreadDispatcher.GetInstance().EnqueueReceivedNotification(notification);
 }
 public void onSentNotification(AndroidJavaObject notificationIntent)
 {
     AndroidReceivedNotificationMainThreadDispatcher.EnqueueReceivedNotification(notificationIntent);
 }