Пример #1
0
    void RemoveAllNotifications()
    {
        #region Android
#if UNITY_ANDROID
        string raw = PlayerPrefs.GetString("NotificationIDs");
        if (!string.IsNullOrEmpty(raw))
        {
            notification_ids = raw.Split(',').Select(x => x.Split(':')).ToDictionary(x => x[0], x => int.Parse(x[1]));
        }
        else
        {
            return;
        }
        foreach (var key in notification_ids.Values)
        {
            AndroidLocalNotification.CancelNotification(key);
        }
        notification_ids.Clear();
        PlayerPrefs.DeleteKey("NotificationIDs");
#endif
        #endregion

        #region iOS
#if UNITY_IOS
        NotificationServices.CancelAllLocalNotifications();
#endif
        #endregion
    }
Пример #2
0
    private void OnGUI()
    {
        // Color is supported only in Android >= 5.0
        GUI.enabled = sleepUntil < Time.time;

        if (GUILayout.Button("5 SECONDS", GUILayout.Height(Screen.height * 0.2f)))
        {
            //AndroidLocalNotification.SendNotification(1, 5, "Title", "Long message text", new Color32(0xff, 0x44, 0x44, 255));
            DateTime _dt = DateTime.Now;
            _dt = _dt.AddSeconds(5);
            ZXNotification.GetInstance().NotificationMessage(3, "测试标题", "测试中文", _dt, false);

            sleepUntil = Time.time + 5;
        }

        if (GUILayout.Button("5 SECONDS BIG ICON", GUILayout.Height(Screen.height * 0.2f)))
        {
            AndroidLocalNotification.SendNotification(2, 5, "Title", "Long message text with big icon", new Color32(0xff, 0x44, 0x44, 255), true, true, true, "app_icon");
            sleepUntil = Time.time + 5;
        }

        if (GUILayout.Button("EVERY 5 SECONDS", GUILayout.Height(Screen.height * 0.2f)))
        {
            AndroidLocalNotification.SendRepeatingNotification(1, 5, 5, "Title", "Long message text", new Color32(0xff, 0x44, 0x44, 255));
            sleepUntil = Time.time + 99999;
        }

        if (GUILayout.Button("10 SECONDS EXACT", GUILayout.Height(Screen.height * 0.2f)))
        {
            AndroidLocalNotification.SendNotification(3, 10, "Title", "Long exact message text", new Color32(0xff, 0x44, 0x44, 255),
                                                      executeMode: AndroidLocalNotification.NotificationExecuteMode.ExactAndAllowWhileIdle);
            sleepUntil = Time.time + 10;
        }

        GUI.enabled = true;

        if (GUILayout.Button("STOP", GUILayout.Height(Screen.height * 0.2f)))
        {
            AndroidLocalNotification.CancelNotification(1);

            AndroidLocalNotification.CancelAllNotifications();

            sleepUntil = 0;
        }
    }