@@ -88,7 +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 . Notification . CollectJni ( ) ;
92
91
JniApi . NotificationBuilder . CollectJni ( ) ;
93
92
JniApi . Bundle . CollectJni ( ) ;
94
93
#else
@@ -233,36 +232,20 @@ public AndroidJavaObject CreateNotificationBuilder(String channelId)
233
232
}
234
233
}
235
234
236
- struct JniApi
237
- {
238
- public NotificationManagerJni NotificationManager ;
239
-
240
- public static JniMethodID FindMethod ( AndroidJavaClass clazz , string name , string signature , bool isStatic )
235
+ struct NotificationJni
241
236
{
242
- #if UNITY_2022_2_OR_NEWER
243
- var method = AndroidJNIHelper . GetMethodID ( clazz . GetRawClass ( ) , name , signature , isStatic ) ;
244
- if ( method == IntPtr . Zero )
245
- throw new Exception ( $ "Method { name } with signature { signature } not found") ;
246
- return method ;
247
- #else
248
- return name ;
249
- #endif
250
- }
251
-
252
- public static class Notification
253
- {
254
- public static AndroidJavaObject EXTRA_TITLE ;
255
- public static AndroidJavaObject EXTRA_TEXT ;
256
- public static AndroidJavaObject EXTRA_SHOW_CHRONOMETER ;
257
- public static AndroidJavaObject EXTRA_BIG_TEXT ;
258
- public static AndroidJavaObject EXTRA_SHOW_WHEN ;
259
- public static int FLAG_AUTO_CANCEL ;
260
- public static int FLAG_GROUP_SUMMARY ;
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 ;
261
244
262
- static JniMethodID getGroup ;
263
- static JniMethodID getSortKey ;
245
+ JniMethodID getGroup ;
246
+ JniMethodID getSortKey ;
264
247
265
- public static void CollectJni ( )
248
+ public void CollectJni ( )
266
249
{
267
250
using ( var notificationClass = new AndroidJavaClass ( "android.app.Notification" ) )
268
251
{
@@ -271,7 +254,7 @@ public static void CollectJni()
271
254
}
272
255
}
273
256
274
- static void CollectConstants ( AndroidJavaClass clazz )
257
+ void CollectConstants ( AndroidJavaClass clazz )
275
258
{
276
259
EXTRA_TITLE = clazz . GetStatic < AndroidJavaObject > ( "EXTRA_TITLE" ) ;
277
260
EXTRA_TEXT = clazz . GetStatic < AndroidJavaObject > ( "EXTRA_TEXT" ) ;
@@ -282,43 +265,60 @@ static void CollectConstants(AndroidJavaClass clazz)
282
265
FLAG_GROUP_SUMMARY = clazz . GetStatic < int > ( "FLAG_GROUP_SUMMARY" ) ;
283
266
}
284
267
285
- static void CollectMethods ( AndroidJavaClass clazz )
268
+ void CollectMethods ( AndroidJavaClass clazz )
286
269
{
287
270
getGroup = JniApi . FindMethod ( clazz , "getGroup" , "()Ljava/lang/String;" , false ) ;
288
271
getSortKey = JniApi . FindMethod ( clazz , "getSortKey" , "()Ljava/lang/String;" , false ) ;
289
272
}
290
273
291
- public static AndroidJavaObject Extras ( AndroidJavaObject notification )
274
+ public AndroidJavaObject Extras ( AndroidJavaObject notification )
292
275
{
293
276
return notification . Get < AndroidJavaObject > ( "extras" ) ;
294
277
}
295
278
296
- public static int Flags ( AndroidJavaObject notification )
279
+ public int Flags ( AndroidJavaObject notification )
297
280
{
298
281
return notification . Get < int > ( "flags" ) ;
299
282
}
300
283
301
- public static int Number ( AndroidJavaObject notification )
284
+ public int Number ( AndroidJavaObject notification )
302
285
{
303
286
return notification . Get < int > ( "number" ) ;
304
287
}
305
288
306
- public static string GetGroup ( AndroidJavaObject notification )
289
+ public string GetGroup ( AndroidJavaObject notification )
307
290
{
308
291
return notification . Call < string > ( getGroup ) ;
309
292
}
310
293
311
- public static string GetSortKey ( AndroidJavaObject notification )
294
+ public string GetSortKey ( AndroidJavaObject notification )
312
295
{
313
296
return notification . Call < string > ( getSortKey ) ;
314
297
}
315
298
316
- internal static long When ( AndroidJavaObject notification )
299
+ internal long When ( AndroidJavaObject notification )
317
300
{
318
301
return notification . Get < long > ( "when" ) ;
319
302
}
320
303
}
321
304
305
+ struct JniApi
306
+ {
307
+ public NotificationManagerJni NotificationManager ;
308
+ public NotificationJni Notification ;
309
+
310
+ public static JniMethodID FindMethod ( AndroidJavaClass clazz , string name , string signature , bool isStatic )
311
+ {
312
+ #if UNITY_2022_2_OR_NEWER
313
+ var method = AndroidJNIHelper . GetMethodID ( clazz . GetRawClass ( ) , name , signature , isStatic ) ;
314
+ if ( method == IntPtr . Zero )
315
+ throw new Exception ( $ "Method { name } with signature { signature } not found") ;
316
+ return method ;
317
+ #else
318
+ return name ;
319
+ #endif
320
+ }
321
+
322
322
public static class NotificationBuilder
323
323
{
324
324
static JniMethodID getExtras ;
@@ -521,6 +521,7 @@ public static bool Initialize()
521
521
var notificationManager = notificationManagerClass . CallStatic < AndroidJavaObject > ( "getNotificationManagerImpl" , context , s_CurrentActivity ) ;
522
522
notificationManager . Call ( "setNotificationCallback" , new NotificationCallback ( ) ) ;
523
523
s_Jni . NotificationManager = new NotificationManagerJni ( notificationManagerClass , notificationManager ) ;
524
+ s_Jni . Notification . CollectJni ( ) ;
524
525
525
526
s_Initialized = true ;
526
527
#endif
@@ -871,41 +872,41 @@ public static AndroidJavaObject CreateNotificationBuilder(int id, AndroidNotific
871
872
872
873
internal static AndroidNotificationIntentData GetNotificationData ( AndroidJavaObject notificationObj )
873
874
{
874
- using ( var extras = JniApi . Notification . Extras ( notificationObj ) )
875
+ using ( var extras = s_Jni . Notification . Extras ( notificationObj ) )
875
876
{
876
877
var id = JniApi . Bundle . GetInt ( extras , s_Jni . NotificationManager . KEY_ID , - 1 ) ;
877
878
if ( id == - 1 )
878
879
return null ;
879
880
880
881
var channelId = s_Jni . NotificationManager . GetNotificationChannelId ( notificationObj ) ;
881
- int flags = JniApi . Notification . Flags ( notificationObj ) ;
882
+ int flags = s_Jni . Notification . Flags ( notificationObj ) ;
882
883
883
884
var notification = new AndroidNotification ( ) ;
884
- notification . Title = JniApi . Bundle . GetString ( extras , JniApi . Notification . EXTRA_TITLE ) ;
885
- notification . Text = JniApi . Bundle . GetString ( extras , JniApi . Notification . EXTRA_TEXT ) ;
885
+ notification . Title = JniApi . Bundle . GetString ( extras , s_Jni . Notification . EXTRA_TITLE ) ;
886
+ notification . Text = JniApi . Bundle . GetString ( extras , s_Jni . Notification . EXTRA_TEXT ) ;
886
887
notification . SmallIcon = JniApi . Bundle . GetString ( extras , s_Jni . NotificationManager . KEY_SMALL_ICON ) ;
887
888
notification . LargeIcon = JniApi . Bundle . GetString ( extras , s_Jni . NotificationManager . KEY_LARGE_ICON ) ;
888
- notification . ShouldAutoCancel = 0 != ( flags & JniApi . Notification . FLAG_AUTO_CANCEL ) ;
889
- notification . UsesStopwatch = JniApi . Bundle . GetBoolean ( extras , JniApi . Notification . EXTRA_SHOW_CHRONOMETER , false ) ;
889
+ notification . ShouldAutoCancel = 0 != ( flags & s_Jni . Notification . FLAG_AUTO_CANCEL ) ;
890
+ notification . UsesStopwatch = JniApi . Bundle . GetBoolean ( extras , s_Jni . Notification . EXTRA_SHOW_CHRONOMETER , false ) ;
890
891
notification . FireTime = JniApi . Bundle . GetLong ( extras , s_Jni . NotificationManager . KEY_FIRE_TIME , - 1L ) . ToDatetime ( ) ;
891
892
notification . RepeatInterval = JniApi . Bundle . GetLong ( extras , s_Jni . NotificationManager . KEY_REPEAT_INTERVAL , - 1L ) . ToTimeSpan ( ) ;
892
893
893
- if ( JniApi . Bundle . ContainsKey ( extras , JniApi . Notification . EXTRA_BIG_TEXT ) )
894
+ if ( JniApi . Bundle . ContainsKey ( extras , s_Jni . Notification . EXTRA_BIG_TEXT ) )
894
895
notification . Style = NotificationStyle . BigTextStyle ;
895
896
else
896
897
notification . Style = NotificationStyle . None ;
897
898
898
899
notification . Color = s_Jni . NotificationManager . GetNotificationColor ( notificationObj ) ;
899
- notification . Number = JniApi . Notification . Number ( notificationObj ) ;
900
+ notification . Number = s_Jni . Notification . Number ( notificationObj ) ;
900
901
notification . IntentData = JniApi . Bundle . GetString ( extras , s_Jni . NotificationManager . KEY_INTENT_DATA ) ;
901
- notification . Group = JniApi . Notification . GetGroup ( notificationObj ) ;
902
- notification . GroupSummary = 0 != ( flags & JniApi . Notification . FLAG_GROUP_SUMMARY ) ;
903
- notification . SortKey = JniApi . Notification . GetSortKey ( notificationObj ) ;
902
+ notification . Group = s_Jni . Notification . GetGroup ( notificationObj ) ;
903
+ notification . GroupSummary = 0 != ( flags & s_Jni . Notification . FLAG_GROUP_SUMMARY ) ;
904
+ notification . SortKey = s_Jni . Notification . GetSortKey ( notificationObj ) ;
904
905
notification . GroupAlertBehaviour = s_Jni . NotificationManager . GetNotificationGroupAlertBehavior ( notificationObj ) . ToGroupAlertBehaviours ( ) ;
905
- var showTimestamp = JniApi . Bundle . GetBoolean ( extras , JniApi . Notification . EXTRA_SHOW_WHEN , false ) ;
906
+ var showTimestamp = JniApi . Bundle . GetBoolean ( extras , s_Jni . Notification . EXTRA_SHOW_WHEN , false ) ;
906
907
notification . ShowTimestamp = showTimestamp ;
907
908
if ( showTimestamp )
908
- notification . CustomTimestamp = JniApi . Notification . When ( notificationObj ) . ToDatetime ( ) ;
909
+ notification . CustomTimestamp = s_Jni . Notification . When ( notificationObj ) . ToDatetime ( ) ;
909
910
910
911
var data = new AndroidNotificationIntentData ( id , channelId , notification ) ;
911
912
data . NativeNotification = notificationObj ;
0 commit comments