Skip to content

Commit c7ea476

Browse files
committed
Use low level field in Notification
1 parent a49b88c commit c7ea476

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,18 @@ struct NotificationJni
245245
JniMethodID getGroup;
246246
JniMethodID getSortKey;
247247

248+
JniFieldID extras;
249+
JniFieldID flags;
250+
JniFieldID number;
251+
JniFieldID when;
252+
248253
public void CollectJni()
249254
{
250255
using (var notificationClass = new AndroidJavaClass("android.app.Notification"))
251256
{
252257
CollectConstants(notificationClass);
253258
CollectMethods(notificationClass);
259+
CollectFields(notificationClass);
254260
}
255261
}
256262

@@ -271,19 +277,27 @@ void CollectMethods(AndroidJavaClass clazz)
271277
getSortKey = JniApi.FindMethod(clazz, "getSortKey", "()Ljava/lang/String;", false);
272278
}
273279

280+
void CollectFields(AndroidJavaClass clazz)
281+
{
282+
extras = JniApi.FindField(clazz, "extras", "Landroid/os/Bundle;", false);
283+
flags = JniApi.FindField(clazz, "flags", "I", false);
284+
number = JniApi.FindField(clazz, "number", "I", false);
285+
when = JniApi.FindField(clazz, "when", "J", false);
286+
}
287+
274288
public AndroidJavaObject Extras(AndroidJavaObject notification)
275289
{
276-
return notification.Get<AndroidJavaObject>("extras");
290+
return notification.Get<AndroidJavaObject>(extras);
277291
}
278292

279293
public int Flags(AndroidJavaObject notification)
280294
{
281-
return notification.Get<int>("flags");
295+
return notification.Get<int>(flags);
282296
}
283297

284298
public int Number(AndroidJavaObject notification)
285299
{
286-
return notification.Get<int>("number");
300+
return notification.Get<int>(number);
287301
}
288302

289303
public string GetGroup(AndroidJavaObject notification)
@@ -298,7 +312,7 @@ public string GetSortKey(AndroidJavaObject notification)
298312

299313
internal long When(AndroidJavaObject notification)
300314
{
301-
return notification.Get<long>("when");
315+
return notification.Get<long>(when);
302316
}
303317
}
304318

0 commit comments

Comments
 (0)