private void Awake() { if (AN_NotificationManager.LastOpenedNotificationRequest != null) { Debug.Log("Looks like the app was launched from notifications request: " + JsonUtility.ToJson(AN_NotificationManager.LastOpenedNotificationRequest)); } AN_NotificationManager.OnNotificationClick.AddSafeListener(this, (request) => { Debug.Log("request.Identifier: " + request.Identifier); Debug.Log("User has opened the local notification request with info: " + JsonUtility.ToJson(request)); }); AN_NotificationManager.OnNotificationReceived.AddSafeListener(this, (request) => { Debug.Log("request.Identifier: " + request.Identifier); Debug.Log("notification request received with info: " + JsonUtility.ToJson(request)); }); m_withLargeIcon.onClick.AddListener(() => { SA_ScreenUtil.TakeScreenshot(256, (screenshot) => { var builder = new AN_NotificationCompat.Builder(); builder.SetContentText("Text"); builder.SetContentTitle("Title"); builder.SetLargeIcon(screenshot); builder.SetSmallIcon("custom_icon"); builder.SetSound("slow_spring_board"); var trigger = new AN_AlarmNotificationTrigger(); trigger.SetDate(TimeSpan.FromSeconds(1)); var id = SA_IdFactory.NextId; var request = new AN_NotificationRequest(id, builder, trigger); AN_NotificationManager.Schedule(request); }); }); m_simple.onClick.AddListener(() => { var builder = new AN_NotificationCompat.Builder(); builder.SetContentText("Text 2"); builder.SetContentTitle("Title 2"); builder.SetSmallIcon("custom_icon"); var trigger = new AN_AlarmNotificationTrigger(); trigger.SetDate(TimeSpan.FromSeconds(5)); var id = SA_IdFactory.NextId; var request = new AN_NotificationRequest(id, builder, trigger); AN_NotificationManager.Schedule(request); }); m_closeApp.onClick.AddListener(() => { Application.Quit(); }); }
protected override void AddNotificationRequestInternal(UM_NotificationRequest request, Action <SA_Result> callback) { try { var builder = new AN_NotificationCompat.Builder(); builder.SetContentTitle(request.Content.Title); builder.SetContentText(request.Content.Body); if (request.Content.BadgeNumber != -1) { builder.SetNumber(request.Content.BadgeNumber); } if (string.IsNullOrEmpty(request.Content.SoundName)) { builder.SetDefaults(AN_Notification.DEFAULT_LIGHTS | AN_Notification.DEFAULT_SOUND); } else { string soundName = SA_AssetDatabase.GetAssetNameWithoutExtension(request.Content.SoundName); builder.SetSound(soundName); } if (!string.IsNullOrEmpty(request.Content.IconName)) { string iconName = SA_AssetDatabase.GetAssetNameWithoutExtension(request.Content.IconName); builder.SetSmallIcon(iconName); } if (request.Content.LargeIcon != null) { builder.SetLargeIcon(request.Content.LargeIcon); } UM_TimeIntervalNotificationTrigger timeIntervalTrigger = (UM_TimeIntervalNotificationTrigger)request.Trigger; var trigger = new AN_AlarmNotificationTrigger(); trigger.SetDate(TimeSpan.FromSeconds(timeIntervalTrigger.Interval)); trigger.SerRepeating(timeIntervalTrigger.Repeating); var android_request = new AN_NotificationRequest(request.Identifier, builder, trigger); AN_NotificationManager.Schedule(android_request); callback.Invoke(new SA_Result()); } catch (Exception ex) { var error = new SA_Error(100, ex.Message); callback.Invoke(new SA_Result(error)); } }
private void AndroidBigTextStyle() { SA_ScreenUtil.TakeScreenshot(256, (screenshot) => { var builder = new AN_NotificationCompat.Builder(); builder.SetContentText("Big Text Style"); builder.SetContentTitle("Big TextStyle Title"); var bigTextStyle = new AN_NotificationCompat.BigTextStyle(); bigTextStyle.BigText("This is test big text style"); builder.SetStyle(bigTextStyle); builder.SetDefaults(AN_Notification.DEFAULT_ALL); var trigger = new AN_AlarmNotificationTrigger(); trigger.SetDate(TimeSpan.FromSeconds(1)); var id = SA_IdFactory.NextId; var request = new AN_NotificationRequest(id, builder, trigger); AN_NotificationManager.Schedule(request); }); }
/// <summary> /// Schedules local notification /// </summary> /// <param name="title"></param> /// <param name="message"></param> /// <param name="triggerTime"></param> /// <param name="customIconName"></param> public void ScheduleNotification(string title, string message, TimeSpan triggerTime, string customIconName = "rg_push_small_icon") { var builder = new AN_NotificationCompat.Builder(); builder.SetContentTitle(title); builder.SetContentText(message); //setting icon for notifications builder.SetSmallIcon(customIconName); var trigger = new AN_AlarmNotificationTrigger(); trigger.SetDate(triggerTime); var notificationId = _currentNotificationScheduleCue; var nRequest = new AN_NotificationRequest(notificationId, builder, trigger); Debug.Log("Local Notification Scheduled in: " + triggerTime + ", invoking: " + title + ", current queue ID: " + _currentNotificationScheduleCue); //increase the queue ID _currentNotificationScheduleCue++; AN_NotificationManager.Schedule(nRequest); }
private void TestNotificationWithVariantId(int variantId) { var builder = new AN_NotificationCompat.Builder(); //should be created automatically builder.SetChanelId("test_chanel"); var icon = SA_IconManager.GetIcon(Color.cyan, 32, 32); builder.SetLargeIcon(icon); var trigger = new AN_AlarmNotificationTrigger(); trigger.SetDate(TimeSpan.FromSeconds(1)); int id = SA_IdFactory.NextId; switch (variantId) { case 1: builder.SetContentText("Default"); builder.SetContentTitle("SetDefaults Test"); builder.SetDefaults(AN_Notification.DEFAULT_LIGHTS | AN_Notification.DEFAULT_SOUND); break; case 2: builder.SetContentText("BigTextStyle"); builder.SetContentTitle("BigTextStyle Title"); var bigTextStyle = new AN_NotificationCompat.BigTextStyle(); bigTextStyle.BigText("This is test big text style"); builder.SetStyle(bigTextStyle); builder.SetDefaults(AN_Notification.DEFAULT_ALL); break; case 3: builder.SetContentText("BigPictureStyle"); builder.SetContentTitle("BigPictureStyle title"); var bigPictureStyle = new AN_NotificationCompat.BigPictureStyle(); bigPictureStyle.BigPicture(SA_IconManager.GetIcon(Color.red, 32, 32)); bigPictureStyle.BigLargeIcon(SA_IconManager.GetIcon(Color.green, 32, 32)); builder.SetStyle(bigPictureStyle); builder.SetDefaults(AN_Notification.DEFAULT_ALL); break; } if (variantId == 4) { SetResult(SA_TestResult.OK); } else { m_sendedRequest = new AN_NotificationRequest(id, builder, trigger); AN_NotificationManager.Schedule(m_sendedRequest); } }