Esempio n. 1
0
    void SetNewNotification()
    {
        AndroidNotification newNotif = new AndroidNotification();

        newNotif.Title    = "You can spin for stars!";
        newNotif.Text     = "Your daily login spin is ready to be collected!";
        newNotif.FireTime = System.DateTime.Now.AddSeconds(30);//GetFireTime();
        identifier        = AndroidNotificationCenter.SendNotification(newNotif, channel.Id);

        AndroidNotificationCenter.NotificationReceivedCallback receivedNotificationHandler = delegate(AndroidNotificationIntentData data)
        {
            var msg = "Notification received: " + data.Id + "\n";
            Debug.Log(msg);
        };


        AndroidNotificationCenter.OnNotificationReceived += receivedNotificationHandler;

        var notificationIntentData = AndroidNotificationCenter.GetLastNotificationIntent();

        if (notificationIntentData != null)
        {
            Debug.Log("App was opened with notification!");
            AndroidNotificationCenter.CancelAllDisplayedNotifications();
        }
    }
Esempio n. 2
0
    public IEnumerator SendNotification_NotificationIsReceived_CallMainThread()
    {
        var gameObjects = new GameObject[1];

        AndroidNotificationCenter.NotificationReceivedCallback receivedNotificationHandler =
            delegate(AndroidNotificationIntentData data)
        {
            gameObjects[0]      = new GameObject();
            gameObjects[0].name = "Hello_World";
            Assert.AreEqual("Hello_World", gameObjects[0].name);
        };

        var n = new AndroidNotification();

        n.Title    = "SendNotification_NotificationIsReceived";
        n.Text     = "SendNotification_NotificationIsReceived Text";
        n.FireTime = System.DateTime.Now;

        Debug.LogWarning("SendNotification_NotificationIsReceived_CallMainThread sends notification");

        int originalId = AndroidNotificationCenter.SendNotification(n, kDefaultTestChannel);

        AndroidNotificationCenter.OnNotificationReceived += receivedNotificationHandler;

        yield return(WaitForNotification(8.0f));

        Debug.LogWarning("SendNotification_NotificationIsReceived_CallMainThread completed");

        AndroidNotificationCenter.OnNotificationReceived -= receivedNotificationHandler;
        Assert.AreEqual(1, currentHandler.receivedNotificationCount);
        Assert.AreEqual(originalId, currentHandler.lastNotification.Id);
        Assert.IsNotNull(gameObjects[0]);
    }
    public IEnumerator SendNotification_NotificationIsReceived_CallMainThread()
    {
        AndroidNotificationCenter.CancelAllNotifications();


        yield return(new WaitForSeconds(3.0f));

        var n = new AndroidNotification();

        n.Title    = "SendNotification_NotificationIsReceived";
        n.Text     = "SendNotification_NotificationIsReceived Text";
        n.FireTime = System.DateTime.Now.AddSeconds(2.0f);


        var current_time = DateTime.Now;

        Debug.LogWarning(string.Format("SendNotification_NotificationIsReceived:::FireTime::: {0}  -> {1}", current_time.ToString(), n.FireTime.ToString()));


        var c = new AndroidNotificationChannel();

        c.Id          = "default_test_channel_5";
        c.Name        = "Default Channel 5";
        c.Description = "test_channel 5";
        c.Importance  = Importance.High;

        AndroidNotificationCenter.RegisterNotificationChannel(c);
        int originalId = AndroidNotificationCenter.SendNotification(n, "default_test_channel_5");


        AndroidNotificationCenter.NotificationReceivedCallback receivedNotificationHandler =
            delegate(AndroidNotificationIntentData data)
        {
            receivedNotificationCount += 1;

            var go = new GameObject();
            go.name = "Hello_World";

            Assert.AreEqual(originalId, data.Id);
            Assert.AreEqual("Hello_World", go.name);
        };


        AndroidNotificationCenter.OnNotificationReceived += receivedNotificationHandler;

        yield return(new WaitForSeconds(8.0f));

        Debug.LogWarning("SendNotification_NotificationIsReceived:::   Assert.AreEqual(1, receivedNotificationCount) receivedNotificationCount: " + receivedNotificationCount.ToString());

        Assert.AreEqual(1, receivedNotificationCount);

        AndroidNotificationCenter.OnNotificationReceived -= receivedNotificationHandler;

        AndroidNotificationCenter.CancelAllNotifications();
        receivedNotificationCount = 0;
    }
    public IEnumerator SendNotificationExplicitID_NotificationIsReceived()
    {
        AndroidNotificationCenter.CancelAllNotifications();


        int originalId = 456;

        yield return(new WaitForSeconds(3.0f));

        var n = new AndroidNotification();

        n.Title    = "SendNotificationExplicitID_NotificationIsReceived : " + originalId.ToString();
        n.Text     = "SendNotificationExplicitID_NotificationIsReceived Text";
        n.FireTime = System.DateTime.Now.AddSeconds(2.0f);
        n.Group    = "test.dummy.group";


        var current_time = DateTime.Now;

        Debug.LogWarning(string.Format("SendNotification_NotificationIsReceived:::FireTime::: {0}  -> {1}", current_time.ToString(), n.FireTime.ToString()));


        var c = new AndroidNotificationChannel();

        c.Id          = "default_test_channel_5";
        c.Name        = "Default Channel 5";
        c.Description = "test_channel 5";
        c.Importance  = Importance.High;

        AndroidNotificationCenter.RegisterNotificationChannel(c);
        AndroidNotificationCenter.SendNotificationWithExplicitID(n, "default_test_channel_5", originalId);


        AndroidNotificationCenter.NotificationReceivedCallback receivedNotificationHandler =
            delegate(AndroidNotificationIntentData data)
        {
            receivedNotificationCount += 1;
            Assert.AreEqual(originalId, data.Id);
            Assert.AreEqual(n.Group, data.Notification.Group);
        };


        AndroidNotificationCenter.OnNotificationReceived += receivedNotificationHandler;

        yield return(new WaitForSeconds(8.0f));

        Debug.LogWarning("SendNotification_NotificationIsReceived:::   Assert.AreEqual(1, receivedNotificationCount) receivedNotificationCount: " + receivedNotificationCount.ToString());

        Assert.AreEqual(1, receivedNotificationCount);

        AndroidNotificationCenter.OnNotificationReceived -= receivedNotificationHandler;

        AndroidNotificationCenter.CancelAllNotifications();
        receivedNotificationCount = 0;
    }
    public void ReceiveCallbackOfNewlyDeliveredNotification()
    {
        AndroidNotificationCenter.NotificationReceivedCallback receivedNotificationHandler =
            delegate(AndroidNotificationIntentData data)
        {
            var msg = "Notification received : " + data.Id + "\n";
            msg += "\n Notification received: ";
            msg += "\n .Title: " + data.Notification.Title;
            msg += "\n .Body: " + data.Notification.Text;
            msg += "\n .Channel: " + data.Channel;
            Debug.Log(msg);
        };

        AndroidNotificationCenter.OnNotificationReceived += receivedNotificationHandler;
    }
Esempio n. 6
0
    void Start()
    {
        AndroidNotificationCenter.NotificationReceivedCallback receivedNotificationHandler =
            delegate(AndroidNotificationIntentData lastNotification)
        {
            if (lastNotification.Channel == "review_ch")
            {
                errorTxt.text = lastNotification.Channel;
                errorObj.SetActive(true);
                reviewBarberFirstName = lastNotification.Notification.IntentData.Split('\t')[0];
                reviewBarberLastName  = lastNotification.Notification.IntentData.Split('\t')[1];
                if (appmanagerClass.SelectedLanguage == 1)
                {
                    barberName.text = "Nume frizer: " + lastNotification.Notification.IntentData.Split('\t')[0] + " " + lastNotification.Notification.IntentData.Split('\t')[1];
                    reviewMenu.SetActive(true);
                }
                else if (appmanagerClass.SelectedLanguage == 2)
                {
                    barberName.text = "Barber name: " + lastNotification.Notification.IntentData.Split('\t')[0] + " " + lastNotification.Notification.IntentData.Split('\t')[1];
                    reviewMenu.SetActive(true);
                }
            }
        };
        AndroidNotificationCenter.OnNotificationReceived     += receivedNotificationHandler;
        Firebase.Messaging.FirebaseMessaging.TokenReceived   += OnTokenReceived;
        Firebase.Messaging.FirebaseMessaging.MessageReceived += OnMessageReceived;
        minutesAfterAppointment = Mathf.RoundToInt(UnityEngine.Random.Range(30f, 80f));
        //Create a channel
        var channel = new AndroidNotificationChannel()
        {
            Id          = "reminder_ch",
            Name        = "Reminder channel",
            Importance  = Importance.High,
            Description = "Reminder notifications",
        };
        var reviewChannel = new AndroidNotificationChannel()
        {
            Id          = "review_ch",
            Name        = "Review channel",
            Importance  = Importance.High,
            Description = "Review notifications",
        };

        AndroidNotificationCenter.RegisterNotificationChannel(channel);
        AndroidNotificationCenter.RegisterNotificationChannel(reviewChannel);
    }
    private void Start()
    {
        defaultNotificationChannel = new AndroidNotificationChannel()
        {
            Id          = "default_channel",
            Name        = "Default Channel",
            Description = "For Generic notifications",
            Importance  = Importance.Default,
        };

        AndroidNotificationCenter.RegisterNotificationChannel(defaultNotificationChannel);


        AndroidNotification notification = new AndroidNotification()
        {
            Title     = "Test Notification!",
            Text      = "This is a test notification!",
            SmallIcon = "app_icon_small",
            LargeIcon = "app_icon_large",
            FireTime  = System.DateTime.Now.AddSeconds(10),
        };

        identifier = AndroidNotificationCenter.SendNotification(notification, "default_channel");


        AndroidNotificationCenter.NotificationReceivedCallback receivedNotificationHandler = delegate(AndroidNotificationIntentData data)
        {
            var msg = "Notification received : " + data.Id + "\n";
            msg += "\n Notification received: ";
            msg += "\n .Title: " + data.Notification.Title;
            msg += "\n .Body: " + data.Notification.Text;
            msg += "\n .Channel: " + data.Channel;
            Debug.Log(msg);
        };

        AndroidNotificationCenter.OnNotificationReceived += receivedNotificationHandler;

        var notificationIntentData = AndroidNotificationCenter.GetLastNotificationIntent();

        if (notificationIntentData != null)
        {
            Debug.Log("App was opened with notification!");
        }
    }
Esempio n. 8
0
    public void CreateRandomNotification(System.DateTime time)
    {
        var channel = new AndroidNotificationChannel()
        {
            Id          = "instajong",
            Name        = "Default Instajong Channel",
            Importance  = Importance.Default,
            Description = "Generic notifications"
        };

        AndroidNotificationCenter.RegisterNotificationChannel(channel);

        _notification _n = GetRandomNotification();

        var _NewNotification = new AndroidNotification()
        {
            Title     = _n._Header,
            Text      = _n._Message,
            Color     = _n._Color,
            FireTime  = time,
            SmallIcon = "icon_0"
        };

        identifier = AndroidNotificationCenter.SendNotification(_NewNotification, channel.Id);

        AndroidNotificationCenter.NotificationReceivedCallback receivedCallback = delegate(AndroidNotificationIntentData data)
        {
            var msg = "Notification received : " + data.Id + "\n";
            msg += "\n Notification received: ";
            msg += "\n Title: " + data.Notification.Title;
            msg += "\n Body: " + data.Notification.Text;
            msg += "\n Channel: " + data.Channel;
        };

        AndroidNotificationCenter.OnNotificationReceived += ReceivedNotificationHandler;

        var notificationIntentData = AndroidNotificationCenter.GetLastNotificationIntent();

        if (notificationIntentData != null)
        {
            Debug.Log("App was opened with notification!");
        }
    }
//    [UnityTest]
    public IEnumerator ScheduleRepeatableNotification_NotificationsAreReceived()
    {
        AndroidNotificationCenter.CancelAllNotifications();

        yield return(new WaitForSeconds(2.0f));

        var n = new AndroidNotification();

        n.Title          = "Repeating Notification Title";
        n.Text           = "Repeating Notification Text";
        n.FireTime       = System.DateTime.Now.AddSeconds(0.5f);
        n.RepeatInterval = new System.TimeSpan(0, 0, 1);

        var c = new AndroidNotificationChannel();

        c.Id          = "default_test_channel_2";
        c.Name        = "Default Channel";
        c.Description = "test_channel";
        c.Importance  = Importance.High;

        AndroidNotificationCenter.RegisterNotificationChannel(c);
        int originalId = AndroidNotificationCenter.SendNotification(n, "default_test_channel_2");

        AndroidNotificationCenter.NotificationReceivedCallback receivedNotificationHandler =
            delegate(AndroidNotificationIntentData data)
        {
            receivedNotificationCount += 1;
            Assert.AreEqual(originalId, data.Id);
        };

        AndroidNotificationCenter.OnNotificationReceived += receivedNotificationHandler;

        //The notification should be repeated every second, so we should get atleast 3.
        yield return(new WaitForSeconds(5.0f));

        Assert.GreaterOrEqual(3, receivedNotificationCount);
        receivedNotificationCount = 0;

        AndroidNotificationCenter.OnNotificationReceived -= receivedNotificationHandler;

        AndroidNotificationCenter.CancelAllNotifications();
    }
Esempio n. 10
0
    public void create_notification(string Notification_Tittle, string Notification_Text)
    {
        Xplorabox_NotificationChannel = new AndroidNotificationChannel()
        {
            Id          = Channel_ID,
            Name        = Channel_Name,
            Description = "For Generic notifications",
            Importance  = Importance.High,
        };

        AndroidNotificationCenter.RegisterNotificationChannel(Xplorabox_NotificationChannel);

        AndroidNotification notification = new AndroidNotification()
        {
            Title     = Notification_Tittle,
            Text      = Notification_Text,
            FireTime  = DateTime.Now.AddSeconds(0.5f),
            SmallIcon = "icon_small",
        };

        var c = AndroidNotificationCenter.SendNotification(notification, Channel_ID);

        AndroidNotificationCenter.NotificationReceivedCallback receivedNotificationHandler = delegate(AndroidNotificationIntentData data)
        {
            var msg = "Notification recieved :" + data.Id + "\n";
            msg += "\n Title :: " + data.Notification.Title;
            msg += "\n Body :: " + data.Notification.Text;
            msg += "\n .channel :: " + data.Channel;
            Debug.Log(msg);
        };

        AndroidNotificationCenter.OnNotificationReceived += receivedNotificationHandler;
        var notificationIntentData = AndroidNotificationCenter.GetLastNotificationIntent();

        if (notificationIntentData != null)
        {
            Debug.Log("App was opened with notification!");
        }
    }
    // Start is called before the first frame update
    void Start()
    {
#if UNITY_ANDROID
        AndroidNotificationCenter.NotificationReceivedCallback receivedNotificationHandler =
            delegate(AndroidNotificationIntentData data)
        {
            var msg = "Notification received : " + data.Id + "\n";
            msg += "\n Notification received: ";
            msg += "\n .Title: " + data.Notification.Title;
            msg += "\n .Body: " + data.Notification.Text;
            msg += "\n .Channel: " + data.Channel;

            Debug.Log(msg);

            txtStatus.text = msg;
        };

        //Get intentinfo
        AndroidNotificationCenter.OnNotificationReceived += receivedNotificationHandler;
        var notificationIntentData = AndroidNotificationCenter.GetLastNotificationIntent();
        if (notificationIntentData != null)
        {
            var id           = notificationIntentData.Id;
            var channel      = notificationIntentData.Channel;
            var notification = notificationIntentData.Notification;


            txtStatus.text += "\n INTENT" + id.ToString() + " " + channel.ToString() + " " + notification.IntentData;
        }
#elif UNITY_IOS
        iOSNotificationCenter.OnRemoteNotificationReceived += remoteNotification =>
        {
            Debug.Log("Remote notification received");
        };
#endif
    }