Skip to content

Commit 141bb22

Browse files
committed
Add button for canceling single notification
1 parent 80a2e89 commit 141bb22

File tree

1 file changed

+13
-0
lines changed
  • TestProjects/com.unity.mobile-notifications-sample/Assets/Scripts

1 file changed

+13
-0
lines changed

TestProjects/com.unity.mobile-notifications-sample/Assets/Scripts/AndroidTest.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class AndroidTest : MonoBehaviour
2121
private Logger m_LOGGER;
2222
private int _notificationExplicitID;
2323
private Button ButtonModifyExplicitID;
24+
private Button ButtonCancelExplicitID;
2425

2526
public int notificationExplicitID
2627
{
@@ -30,6 +31,7 @@ public int notificationExplicitID
3031
_notificationExplicitID = value;
3132
bool buttonsEnabled = _notificationExplicitID != 0;
3233
ButtonModifyExplicitID.interactable = buttonsEnabled;
34+
ButtonCancelExplicitID.interactable = buttonsEnabled;
3335
}
3436
}
3537

@@ -116,6 +118,7 @@ private void InstantiateAllTestButtons()
116118
m_groups["Modify"] = new OrderedDictionary();
117119
//m_groups["Modify"]["Create notification preset"] = new Action(() => { });
118120
m_groups["Modify"]["Modify pending Explicit notification"] = new Action(() => { ModifyExplicitNotification(); });
121+
m_groups["Modify"]["Cancel pending Explicit notification"] = new Action(() => { CancelExplicitNotification(); });
119122

120123
m_groups["Send"] = new OrderedDictionary();
121124
foreach (AndroidNotificationTemplate template in Resources.LoadAll("AndroidNotifications", typeof(AndroidNotificationTemplate)))
@@ -231,6 +234,8 @@ private void InstantiateAllTestButtons()
231234
}
232235
ButtonModifyExplicitID = GameObject.Find("Modify/Modify pending Explicit notification").GetComponent<Button>();
233236
ButtonModifyExplicitID.interactable = false;
237+
ButtonCancelExplicitID = GameObject.Find("Modify/Cancel pending Explicit notification").GetComponent<Button>();
238+
ButtonCancelExplicitID.interactable = false;
234239
m_gameObjectReferences.ButtonGroupTemplate.gameObject.SetActive(false);
235240
}
236241

@@ -248,6 +253,14 @@ public void ModifyExplicitNotification()
248253
.Properties(template, 1);
249254
}
250255

256+
public void CancelExplicitNotification()
257+
{
258+
AndroidNotificationCenter.CancelScheduledNotification(notificationExplicitID);
259+
notificationExplicitID = 0;
260+
m_LOGGER
261+
.Blue($"[{DateTime.Now.ToString("HH:mm:ss.ffffff")}] Call {MethodBase.GetCurrentMethod().Name}");
262+
}
263+
251264
public void SendNotification(AndroidNotification notification, string channel = "default_channel", int notificationID = 0, bool log = true)
252265
{
253266
if (log)

0 commit comments

Comments
 (0)