@@ -88,8 +88,6 @@ public NotificationManagerJni(AndroidJavaClass clazz, AndroidJavaObject obj)
88
88
KEY_SMALL_ICON = clazz . GetStatic < AndroidJavaObject > ( "KEY_SMALL_ICON" ) ;
89
89
90
90
CollectMethods ( clazz ) ;
91
- JniApi . NotificationBuilder . CollectJni ( ) ;
92
- JniApi . Bundle . CollectJni ( ) ;
93
91
#else
94
92
KEY_FIRE_TIME = null ;
95
93
KEY_ID = null ;
@@ -233,80 +231,89 @@ public AndroidJavaObject CreateNotificationBuilder(String channelId)
233
231
}
234
232
235
233
struct NotificationJni
236
- {
237
- public AndroidJavaObject EXTRA_TITLE ;
238
- public AndroidJavaObject EXTRA_TEXT ;
239
- public AndroidJavaObject EXTRA_SHOW_CHRONOMETER ;
240
- public AndroidJavaObject EXTRA_BIG_TEXT ;
241
- public AndroidJavaObject EXTRA_SHOW_WHEN ;
242
- public int FLAG_AUTO_CANCEL ;
243
- public int FLAG_GROUP_SUMMARY ;
234
+ {
235
+ public AndroidJavaObject EXTRA_TITLE ;
236
+ public AndroidJavaObject EXTRA_TEXT ;
237
+ public AndroidJavaObject EXTRA_SHOW_CHRONOMETER ;
238
+ public AndroidJavaObject EXTRA_BIG_TEXT ;
239
+ public AndroidJavaObject EXTRA_SHOW_WHEN ;
240
+ public int FLAG_AUTO_CANCEL ;
241
+ public int FLAG_GROUP_SUMMARY ;
244
242
245
- JniMethodID getGroup ;
246
- JniMethodID getSortKey ;
243
+ JniMethodID getGroup ;
244
+ JniMethodID getSortKey ;
247
245
248
- public void CollectJni ( )
246
+ public void CollectJni ( )
247
+ {
248
+ using ( var notificationClass = new AndroidJavaClass ( "android.app.Notification" ) )
249
249
{
250
- using ( var notificationClass = new AndroidJavaClass ( "android.app.Notification" ) )
251
- {
252
- CollectConstants ( notificationClass ) ;
253
- CollectMethods ( notificationClass ) ;
254
- }
250
+ CollectConstants ( notificationClass ) ;
251
+ CollectMethods ( notificationClass ) ;
255
252
}
253
+ }
256
254
257
- void CollectConstants ( AndroidJavaClass clazz )
258
- {
259
- EXTRA_TITLE = clazz . GetStatic < AndroidJavaObject > ( "EXTRA_TITLE" ) ;
260
- EXTRA_TEXT = clazz . GetStatic < AndroidJavaObject > ( "EXTRA_TEXT" ) ;
261
- EXTRA_SHOW_CHRONOMETER = clazz . GetStatic < AndroidJavaObject > ( "EXTRA_SHOW_CHRONOMETER" ) ;
262
- EXTRA_BIG_TEXT = clazz . GetStatic < AndroidJavaObject > ( "EXTRA_BIG_TEXT" ) ;
263
- EXTRA_SHOW_WHEN = clazz . GetStatic < AndroidJavaObject > ( "EXTRA_SHOW_WHEN" ) ;
264
- FLAG_AUTO_CANCEL = clazz . GetStatic < int > ( "FLAG_AUTO_CANCEL" ) ;
265
- FLAG_GROUP_SUMMARY = clazz . GetStatic < int > ( "FLAG_GROUP_SUMMARY" ) ;
266
- }
255
+ void CollectConstants ( AndroidJavaClass clazz )
256
+ {
257
+ EXTRA_TITLE = clazz . GetStatic < AndroidJavaObject > ( "EXTRA_TITLE" ) ;
258
+ EXTRA_TEXT = clazz . GetStatic < AndroidJavaObject > ( "EXTRA_TEXT" ) ;
259
+ EXTRA_SHOW_CHRONOMETER = clazz . GetStatic < AndroidJavaObject > ( "EXTRA_SHOW_CHRONOMETER" ) ;
260
+ EXTRA_BIG_TEXT = clazz . GetStatic < AndroidJavaObject > ( "EXTRA_BIG_TEXT" ) ;
261
+ EXTRA_SHOW_WHEN = clazz . GetStatic < AndroidJavaObject > ( "EXTRA_SHOW_WHEN" ) ;
262
+ FLAG_AUTO_CANCEL = clazz . GetStatic < int > ( "FLAG_AUTO_CANCEL" ) ;
263
+ FLAG_GROUP_SUMMARY = clazz . GetStatic < int > ( "FLAG_GROUP_SUMMARY" ) ;
264
+ }
267
265
268
- void CollectMethods ( AndroidJavaClass clazz )
269
- {
270
- getGroup = JniApi . FindMethod ( clazz , "getGroup" , "()Ljava/lang/String;" , false ) ;
271
- getSortKey = JniApi . FindMethod ( clazz , "getSortKey" , "()Ljava/lang/String;" , false ) ;
272
- }
266
+ void CollectMethods ( AndroidJavaClass clazz )
267
+ {
268
+ getGroup = JniApi . FindMethod ( clazz , "getGroup" , "()Ljava/lang/String;" , false ) ;
269
+ getSortKey = JniApi . FindMethod ( clazz , "getSortKey" , "()Ljava/lang/String;" , false ) ;
270
+ }
273
271
274
- public AndroidJavaObject Extras ( AndroidJavaObject notification )
275
- {
276
- return notification . Get < AndroidJavaObject > ( "extras" ) ;
277
- }
272
+ public AndroidJavaObject Extras ( AndroidJavaObject notification )
273
+ {
274
+ return notification . Get < AndroidJavaObject > ( "extras" ) ;
275
+ }
278
276
279
- public int Flags ( AndroidJavaObject notification )
280
- {
281
- return notification . Get < int > ( "flags" ) ;
282
- }
277
+ public int Flags ( AndroidJavaObject notification )
278
+ {
279
+ return notification . Get < int > ( "flags" ) ;
280
+ }
283
281
284
- public int Number ( AndroidJavaObject notification )
285
- {
286
- return notification . Get < int > ( "number" ) ;
287
- }
282
+ public int Number ( AndroidJavaObject notification )
283
+ {
284
+ return notification . Get < int > ( "number" ) ;
285
+ }
288
286
289
- public string GetGroup ( AndroidJavaObject notification )
290
- {
291
- return notification . Call < string > ( getGroup ) ;
292
- }
287
+ public string GetGroup ( AndroidJavaObject notification )
288
+ {
289
+ return notification . Call < string > ( getGroup ) ;
290
+ }
293
291
294
- public string GetSortKey ( AndroidJavaObject notification )
295
- {
296
- return notification . Call < string > ( getSortKey ) ;
297
- }
292
+ public string GetSortKey ( AndroidJavaObject notification )
293
+ {
294
+ return notification . Call < string > ( getSortKey ) ;
295
+ }
298
296
299
- internal long When ( AndroidJavaObject notification )
300
- {
301
- return notification . Get < long > ( "when" ) ;
302
- }
297
+ internal long When ( AndroidJavaObject notification )
298
+ {
299
+ return notification . Get < long > ( "when" ) ;
303
300
}
301
+ }
304
302
305
303
struct JniApi
306
304
{
307
305
public NotificationManagerJni NotificationManager ;
308
306
public NotificationJni Notification ;
309
307
308
+ public JniApi ( AndroidJavaClass notificationManagerClass , AndroidJavaObject notificationManager )
309
+ {
310
+ NotificationManager = new NotificationManagerJni ( notificationManagerClass , notificationManager ) ;
311
+ Notification = default ;
312
+ Notification . CollectJni ( ) ;
313
+ JniApi . NotificationBuilder . CollectJni ( ) ;
314
+ JniApi . Bundle . CollectJni ( ) ;
315
+ }
316
+
310
317
public static JniMethodID FindMethod ( AndroidJavaClass clazz , string name , string signature , bool isStatic )
311
318
{
312
319
#if UNITY_2022_2_OR_NEWER
@@ -520,8 +527,7 @@ public static bool Initialize()
520
527
var notificationManagerClass = new AndroidJavaClass ( "com.unity.androidnotifications.UnityNotificationManager" ) ;
521
528
var notificationManager = notificationManagerClass . CallStatic < AndroidJavaObject > ( "getNotificationManagerImpl" , context , s_CurrentActivity ) ;
522
529
notificationManager . Call ( "setNotificationCallback" , new NotificationCallback ( ) ) ;
523
- s_Jni . NotificationManager = new NotificationManagerJni ( notificationManagerClass , notificationManager ) ;
524
- s_Jni . Notification . CollectJni ( ) ;
530
+ s_Jni = new JniApi ( notificationManagerClass , notificationManager ) ;
525
531
526
532
s_Initialized = true ;
527
533
#endif
0 commit comments