Skip to content

Commit de31856

Browse files
committed
Update test project with permission stuff
1 parent d9b1a18 commit de31856

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

TestProjects/Main/Assets/Scripts/AndroidTest.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ void Start()
9393
((Action)m_groups["Channels"]["Create Secondary Simple Channel"]).Invoke();
9494
((Action)m_groups["Channels"]["Create Fancy Channel"]).Invoke();
9595
m_LOGGER.Clear().White("Welcome!");
96+
97+
HandleNotificationPermission();
9698
HandleLastNotificationIntent();
9799
}
98100

@@ -103,10 +105,25 @@ void OnApplicationPause(bool isPaused)
103105
.Gray($"isPaused = {isPaused}", 1);
104106
if (isPaused == false)
105107
{
108+
HandleNotificationPermission();
106109
HandleLastNotificationIntent();
107110
}
108111
}
109112

113+
private void HandleNotificationPermission()
114+
{
115+
var permission = AndroidNotificationCenter.UserPermissionToPost;
116+
switch (permission)
117+
{
118+
case PermissionStatus.Allowed:
119+
m_LOGGER.Green("Permission granted to post notifications");
120+
break;
121+
default:
122+
m_LOGGER.Red("No permission to post notifications: " + permission);
123+
break;
124+
}
125+
}
126+
110127
private void HandleLastNotificationIntent()
111128
{
112129
AndroidNotificationIntentData notificationIntentData = AndroidNotificationCenter.GetLastNotificationIntent();
@@ -159,6 +176,7 @@ private void InstantiateAllTestButtons()
159176
m_groups["General"]["Open Settings"] = new Action(() => { AndroidNotificationCenter.OpenNotificationSettings(); });
160177
m_groups["General"]["Notification batch size: "+NotificationBatchSizes[_CurrentNotificationBatchSizeIndex]] = new Action(() => { ChangeNotificationBatchSize(NotificationBatchSizes); });
161178
m_groups["General"]["Reset notification counter"] = new Action(() => { NotificationCounter = 0; });
179+
m_groups["General"]["Request permission"] = new Action(() => { RequestNotificationPermission(); });
162180

163181
m_groups["Modify"] = new OrderedDictionary();
164182
//m_groups["Modify"]["Create notification preset"] = new Action(() => { });
@@ -270,6 +288,31 @@ private void InstantiateAllTestButtons()
270288
m_gameObjectReferences.ButtonGroupTemplate.gameObject.SetActive(false);
271289
}
272290

291+
void RequestNotificationPermission()
292+
{
293+
var permission = AndroidNotificationCenter.UserPermissionToPost;
294+
if (permission == PermissionStatus.Allowed)
295+
m_LOGGER.Green("Already authorized");
296+
if (permission == PermissionStatus.DeniedDontAskAgain)
297+
m_LOGGER.Red("Denied, don't ask again");
298+
else
299+
{
300+
m_LOGGER.Blue("Requesting permission");
301+
permission = AndroidNotificationCenter.RequestPermissionToPost();
302+
switch (permission)
303+
{
304+
case PermissionStatus.Allowed:
305+
m_LOGGER.Green("Permission granted");
306+
break;
307+
case PermissionStatus.RequestPending:
308+
return;
309+
default:
310+
m_LOGGER.Red(permission.ToString());
311+
break;
312+
}
313+
}
314+
}
315+
273316

274317
public void ChangeNotificationBatchSize(int[] notificationBatchSizes)
275318
{

0 commit comments

Comments
 (0)