@@ -93,6 +93,8 @@ void Start()
93
93
( ( Action ) m_groups [ "Channels" ] [ "Create Secondary Simple Channel" ] ) . Invoke ( ) ;
94
94
( ( Action ) m_groups [ "Channels" ] [ "Create Fancy Channel" ] ) . Invoke ( ) ;
95
95
m_LOGGER . Clear ( ) . White ( "Welcome!" ) ;
96
+
97
+ HandleNotificationPermission ( ) ;
96
98
HandleLastNotificationIntent ( ) ;
97
99
}
98
100
@@ -103,10 +105,25 @@ void OnApplicationPause(bool isPaused)
103
105
. Gray ( $ "isPaused = { isPaused } ", 1 ) ;
104
106
if ( isPaused == false )
105
107
{
108
+ HandleNotificationPermission ( ) ;
106
109
HandleLastNotificationIntent ( ) ;
107
110
}
108
111
}
109
112
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
+
110
127
private void HandleLastNotificationIntent ( )
111
128
{
112
129
AndroidNotificationIntentData notificationIntentData = AndroidNotificationCenter . GetLastNotificationIntent ( ) ;
@@ -159,6 +176,7 @@ private void InstantiateAllTestButtons()
159
176
m_groups [ "General" ] [ "Open Settings" ] = new Action ( ( ) => { AndroidNotificationCenter . OpenNotificationSettings ( ) ; } ) ;
160
177
m_groups [ "General" ] [ "Notification batch size: " + NotificationBatchSizes [ _CurrentNotificationBatchSizeIndex ] ] = new Action ( ( ) => { ChangeNotificationBatchSize ( NotificationBatchSizes ) ; } ) ;
161
178
m_groups [ "General" ] [ "Reset notification counter" ] = new Action ( ( ) => { NotificationCounter = 0 ; } ) ;
179
+ m_groups [ "General" ] [ "Request permission" ] = new Action ( ( ) => { RequestNotificationPermission ( ) ; } ) ;
162
180
163
181
m_groups [ "Modify" ] = new OrderedDictionary ( ) ;
164
182
//m_groups["Modify"]["Create notification preset"] = new Action(() => { });
@@ -270,6 +288,31 @@ private void InstantiateAllTestButtons()
270
288
m_gameObjectReferences . ButtonGroupTemplate . gameObject . SetActive ( false ) ;
271
289
}
272
290
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
+
273
316
274
317
public void ChangeNotificationBatchSize ( int [ ] notificationBatchSizes )
275
318
{
0 commit comments