Skip to content

Commit 23c0915

Browse files
committed
Merge branch 'master' into android/refactor-threading
2 parents 68df1b6 + 3f1de8f commit 23c0915

File tree

15 files changed

+847
-154
lines changed

15 files changed

+847
-154
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: fb7d100a40edf48f99686ea68a90ff4c, type: 3}
13+
m_Name: Not shown in foreground
14+
m_EditorClassIdentifier:
15+
ButtonName: Not shown in foreground
16+
Channel: default_channel
17+
FireInSeconds: 10
18+
NotificationID: 0
19+
Title: Not in foreground
20+
Text: This notifications should not appear when app is in foreground
21+
SmallIcon:
22+
LargeIcon:
23+
NotificationStyle: 0
24+
Color: {r: 0, g: 0, b: 0, a: 1}
25+
Number: -1
26+
ShouldAutoCancel: 0
27+
UsesStopWatch: 0
28+
Group:
29+
GroupSummary: 0
30+
GroupAlertBehaviours: 0
31+
SortKey:
32+
IntentData:
33+
ShowTimestamp: 0
34+
RepeatInterval: 0
35+
ShowInForeground: 0

TestProjects/com.unity.mobile-notifications-sample/Assets/Resources/AndroidNotifications/Not shown in foreground.asset.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class AndroidTest : MonoBehaviour
2222
private int _notificationExplicitID;
2323
private Button ButtonModifyExplicitID;
2424
private Button ButtonCancelExplicitID;
25+
private Button ButtonCheckStatusExplicitID;
2526

2627
public int notificationExplicitID
2728
{
@@ -32,6 +33,7 @@ public int notificationExplicitID
3233
bool buttonsEnabled = _notificationExplicitID != 0;
3334
ButtonModifyExplicitID.interactable = buttonsEnabled;
3435
ButtonCancelExplicitID.interactable = buttonsEnabled;
36+
ButtonCheckStatusExplicitID.interactable = buttonsEnabled;
3537
}
3638
}
3739

@@ -60,6 +62,7 @@ void OnNotificationReceivedHandler(AndroidNotificationIntentData notificationInt
6062
.Properties(notificationIntentData.Notification, 1);
6163
if (notificationIntentData.Id == notificationExplicitID)
6264
{
65+
AndroidNotificationCenter.CheckScheduledNotificationStatus(notificationExplicitID);
6366
notificationExplicitID = 0;
6467
}
6568
}
@@ -119,6 +122,8 @@ private void InstantiateAllTestButtons()
119122
//m_groups["Modify"]["Create notification preset"] = new Action(() => { });
120123
m_groups["Modify"]["Modify pending Explicit notification"] = new Action(() => { ModifyExplicitNotification(); });
121124
m_groups["Modify"]["Cancel pending Explicit notification"] = new Action(() => { CancelExplicitNotification(); });
125+
m_groups["Modify"]["Check status of Explicit notification"] = new Action(() => { CheckStatusOfExplicitNotification (); });
126+
122127

123128
m_groups["Send"] = new OrderedDictionary();
124129
foreach (AndroidNotificationTemplate template in Resources.LoadAll("AndroidNotifications", typeof(AndroidNotificationTemplate)))
@@ -130,6 +135,7 @@ private void InstantiateAllTestButtons()
130135
{
131136
Title = template.Title,
132137
Text = template.Text,
138+
133139
SmallIcon = template.SmallIcon,
134140
LargeIcon = template.LargeIcon,
135141
Style = template.NotificationStyle,
@@ -143,7 +149,8 @@ private void InstantiateAllTestButtons()
143149
SortKey = template.SortKey,
144150
IntentData = template.IntentData,
145151
ShowTimestamp = template.ShowTimestamp,
146-
RepeatInterval = TimeSpan.FromSeconds(template.RepeatInterval)
152+
RepeatInterval = TimeSpan.FromSeconds(template.RepeatInterval),
153+
ShowInForeground = template.ShowInForeground,
147154
},
148155
template.Channel, template.NotificationID
149156
);
@@ -236,6 +243,9 @@ private void InstantiateAllTestButtons()
236243
ButtonModifyExplicitID.interactable = false;
237244
ButtonCancelExplicitID = GameObject.Find("Modify/Cancel pending Explicit notification").GetComponent<Button>();
238245
ButtonCancelExplicitID.interactable = false;
246+
ButtonCheckStatusExplicitID = GameObject.Find("Modify/Check status of Explicit notification").GetComponent<Button>();
247+
ButtonCheckStatusExplicitID.interactable = false;
248+
239249
m_gameObjectReferences.ButtonGroupTemplate.gameObject.SetActive(false);
240250
}
241251

@@ -261,6 +271,13 @@ public void CancelExplicitNotification()
261271
.Blue($"[{DateTime.Now.ToString("HH:mm:ss.ffffff")}] Call {MethodBase.GetCurrentMethod().Name}");
262272
}
263273

274+
public void CheckStatusOfExplicitNotification()
275+
{
276+
m_LOGGER
277+
.Blue($"[{DateTime.Now.ToString("HH:mm:ss.ffffff")}] Explicit notification (ID:{notificationExplicitID}) status: {AndroidNotificationCenter.CheckScheduledNotificationStatus(notificationExplicitID)}");
278+
279+
}
280+
264281
public void SendNotification(AndroidNotification notification, string channel = "default_channel", int notificationID = 0, bool log = true)
265282
{
266283
if (log)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class AndroidNotificationTemplate : ScriptableObject
3636
[TextArea] public string IntentData = "";
3737
public bool ShowTimestamp = false;
3838
public long RepeatInterval;
39+
public bool ShowInForeground = true;
3940
#endif
4041
}
4142
}

com.unity.mobile.notifications/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
All notable changes to this package will be documented in this file.
44

5+
## [2.0.2] - 2022-05-13
6+
7+
### Changes & Improvements:
8+
- [Android] - AndroidNotificationCenter.CheckScheduledNotificationStatus now works on devices with all API levels
9+
10+
### Fixes:
11+
- [Android] [issue 186](https://github.com/Unity-Technologies/com.unity.mobile.notifications/issues/186) Mitigate OutOfMemory errors causing application crash
12+
- [Android] [issue 188](https://github.com/Unity-Technologies/com.unity.mobile.notifications/issues/188) Fix unguarded API usage from level 23
13+
514
## [2.0.1] - 2022-04-15
615

716
### Fixes:

com.unity.mobile.notifications/Runtime/Android/AndroidNotification.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,21 @@ public DateTime CustomTimestamp
177177
}
178178
}
179179

180+
/// <summary>
181+
/// Set this notification to be shown when app is in the foreground (default: true).
182+
/// </summary>
183+
public bool ShowInForeground
184+
{
185+
get => !m_SilentInForeground;
186+
set => m_SilentInForeground = !value;
187+
}
188+
180189
internal bool ShowCustomTimestamp { get; set; }
181190

182191
private Color m_Color;
183192
private TimeSpan m_RepeatInterval;
184193
private DateTime m_CustomTimestamp;
194+
private bool m_SilentInForeground;
185195

186196
/// <summary>
187197
/// Create a notification struct with all optional fields set to default values.
@@ -212,6 +222,7 @@ public AndroidNotification(string title, string text, DateTime fireTime)
212222
m_RepeatInterval = (-1L).ToTimeSpan();
213223
m_Color = new Color(0, 0, 0, 0);
214224
m_CustomTimestamp = (-1L).ToDatetime();
225+
m_SilentInForeground = false;
215226
}
216227

217228
/// <summary>

com.unity.mobile.notifications/Runtime/Android/AndroidNotificationCallback.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using UnityEngine;
23

34
namespace Unity.Notifications.Android
@@ -8,6 +9,17 @@ public NotificationCallback() : base("com.unity.androidnotifications.Notificatio
89
{
910
}
1011

12+
public override AndroidJavaObject Invoke(string methodName, AndroidJavaObject[] args)
13+
{
14+
if (methodName.Equals("onSentNotification", StringComparison.InvariantCulture) && args != null && args.Length == 1)
15+
{
16+
onSentNotification(args[0]);
17+
return null;
18+
}
19+
20+
return base.Invoke(methodName, args);
21+
}
22+
1123
public void onSentNotification(AndroidJavaObject notification)
1224
{
1325
AndroidReceivedNotificationMainThreadDispatcher.GetInstance().EnqueueReceivedNotification(notification);

0 commit comments

Comments
 (0)