Skip to content

Commit 202dc1f

Browse files
committed
Make pending intent helpers non-static and private
1 parent 1c43c45 commit 202dc1f

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

com.unity.mobile.notifications/Runtime/Android/Plugins/com/unity/androidnotifications/UnityNotificationManager.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ private void scheduleAlarmWithNotification(Class activityClass, Notification.Bui
362362
mScheduledNotifications.putIfAbsent(Integer.valueOf(id), notificationBuilder);
363363
intent.putExtra(KEY_NOTIFICATION_ID, id);
364364

365-
PendingIntent broadcast = getBroadcastPendingIntent(mContext, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
365+
PendingIntent broadcast = getBroadcastPendingIntent(id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
366366
UnityNotificationManager.scheduleNotificationIntentAlarm(mContext, repeatInterval, fireTime, broadcast);
367367
}
368368

@@ -385,15 +385,15 @@ private Notification buildNotificationForSending(Class openActivity, Notificatio
385385
int id = builder.getExtras().getInt(KEY_ID, -1);
386386
Intent openAppIntent = buildOpenAppIntent(openActivity);
387387
openAppIntent.putExtra(KEY_NOTIFICATION_ID, id);
388-
PendingIntent pendingIntent = getActivityPendingIntent(mContext, id, openAppIntent, 0);
388+
PendingIntent pendingIntent = getActivityPendingIntent(id, openAppIntent, 0);
389389
builder.setContentIntent(pendingIntent);
390390

391391
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
392392
// Can't check StatusBar notifications pre-M, so ask to be notified when dismissed
393393
Intent deleteIntent = new Intent(mContext, UnityNotificationManager.class);
394394
deleteIntent.setAction(KEY_NOTIFICATION_DISMISSED); // need action to distinguish intent from content one
395395
deleteIntent.putExtra(KEY_NOTIFICATION_DISMISSED, id);
396-
PendingIntent deletePending = getBroadcastPendingIntent(mContext, id, deleteIntent, 0);
396+
PendingIntent deletePending = getBroadcastPendingIntent(id, deleteIntent, 0);
397397
builder.setDeleteIntent(deletePending);
398398
}
399399

@@ -432,7 +432,7 @@ private Set<String> findInvalidNotificationIds(Set<String> ids) {
432432
for (String id : ids) {
433433
// Get the given broadcast PendingIntent by id as request code.
434434
// FLAG_NO_CREATE is set to return null if the described PendingIntent doesn't exist.
435-
PendingIntent broadcast = getBroadcastPendingIntent(mContext, Integer.valueOf(id), intent, PendingIntent.FLAG_NO_CREATE);
435+
PendingIntent broadcast = getBroadcastPendingIntent(Integer.valueOf(id), intent, PendingIntent.FLAG_NO_CREATE);
436436
if (broadcast == null) {
437437
invalid.add(id);
438438
}
@@ -471,18 +471,18 @@ private Intent buildNotificationIntent() {
471471
return intent;
472472
}
473473

474-
public static PendingIntent getActivityPendingIntent(Context context, int id, Intent intent, int flags) {
474+
private PendingIntent getActivityPendingIntent(int id, Intent intent, int flags) {
475475
if (Build.VERSION.SDK_INT >= 23)
476-
return PendingIntent.getActivity(context, id, intent, flags | PendingIntent.FLAG_IMMUTABLE);
476+
return PendingIntent.getActivity(mContext, id, intent, flags | PendingIntent.FLAG_IMMUTABLE);
477477
else
478-
return PendingIntent.getActivity(context, id, intent, flags);
478+
return PendingIntent.getActivity(mContext, id, intent, flags);
479479
}
480480

481-
public static PendingIntent getBroadcastPendingIntent(Context context, int id, Intent intent, int flags) {
481+
private PendingIntent getBroadcastPendingIntent(int id, Intent intent, int flags) {
482482
if (Build.VERSION.SDK_INT >= 23)
483-
return PendingIntent.getBroadcast(context, id, intent, flags | PendingIntent.FLAG_IMMUTABLE);
483+
return PendingIntent.getBroadcast(mContext, id, intent, flags | PendingIntent.FLAG_IMMUTABLE);
484484
else
485-
return PendingIntent.getBroadcast(context, id, intent, flags);
485+
return PendingIntent.getBroadcast(mContext, id, intent, flags);
486486
}
487487

488488
// Save the notification intent to SharedPreferences if reschedule_on_restart is true,
@@ -585,7 +585,7 @@ public int checkNotificationStatus(int id) {
585585
// Check if the pending notification with the given id has been registered.
586586
public boolean checkIfPendingNotificationIsRegistered(int id) {
587587
Intent intent = new Intent(mActivity, UnityNotificationManager.class);
588-
return (getBroadcastPendingIntent(mContext, id, intent, PendingIntent.FLAG_NO_CREATE) != null);
588+
return (getBroadcastPendingIntent(id, intent, PendingIntent.FLAG_NO_CREATE) != null);
589589
}
590590

591591
// Cancel all the pending notifications.
@@ -613,7 +613,7 @@ public void cancelPendingNotification(int id) {
613613
// Cancel a pending notification by id.
614614
void cancelPendingNotificationIntent(int id) {
615615
Intent intent = new Intent(mContext, UnityNotificationManager.class);
616-
PendingIntent broadcast = getBroadcastPendingIntent(mContext, id, intent, PendingIntent.FLAG_NO_CREATE);
616+
PendingIntent broadcast = getBroadcastPendingIntent(id, intent, PendingIntent.FLAG_NO_CREATE);
617617

618618
if (broadcast != null) {
619619
AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);

0 commit comments

Comments
 (0)