Skip to content

Commit 2e84fdb

Browse files
committed
Merge getNotificationChannels
1 parent 48c8ea0 commit 2e84fdb

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,15 +282,26 @@ public void deleteNotificationChannel(String id) {
282282
}
283283

284284
public NotificationChannelWrapper[] getNotificationChannels() {
285-
SharedPreferences prefs = mContext.getSharedPreferences(NOTIFICATION_CHANNELS_SHARED_PREFS, Context.MODE_PRIVATE);
286-
Set<String> channelIdsSet = prefs.getStringSet(NOTIFICATION_CHANNELS_SHARED_PREFS_KEY, new HashSet());
285+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
286+
List<NotificationChannel> channels = getNotificationManager().getNotificationChannels();
287+
NotificationChannelWrapper[] channelList = new NotificationChannelWrapper[channels.size()];
288+
int i = 0;
289+
for (NotificationChannel ch : channels) {
290+
channelList[i++] = notificationChannelToWrapper(ch);
291+
}
292+
293+
return channelList;
294+
} else {
295+
SharedPreferences prefs = mContext.getSharedPreferences(NOTIFICATION_CHANNELS_SHARED_PREFS, Context.MODE_PRIVATE);
296+
Set<String> channelIdsSet = prefs.getStringSet(NOTIFICATION_CHANNELS_SHARED_PREFS_KEY, new HashSet());
287297

288-
NotificationChannelWrapper[] channels = new NotificationChannelWrapper[channelIdsSet.size()];
289-
int i = 0;
290-
for (String k : channelIdsSet) {
291-
channels[i++] = getNotificationChannel(k);
298+
NotificationChannelWrapper[] channels = new NotificationChannelWrapper[channelIdsSet.size()];
299+
int i = 0;
300+
for (String k : channelIdsSet) {
301+
channels[i++] = getNotificationChannel(k);
302+
}
303+
return channels;
292304
}
293-
return channels;
294305
}
295306

296307
// This is called from Unity managed code to call AlarmManager to set a broadcast intent for sending a notification.

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,4 @@ public class UnityNotificationManagerOreo extends UnityNotificationManager {
1212
public UnityNotificationManagerOreo(Context context, Activity activity) {
1313
super(context, activity);
1414
}
15-
16-
@Override
17-
public NotificationChannelWrapper[] getNotificationChannels() {
18-
assert Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
19-
20-
List<NotificationChannel> channels = getNotificationManager().getNotificationChannels();
21-
NotificationChannelWrapper[] channelList = new NotificationChannelWrapper[channels.size()];
22-
int i = 0;
23-
for (NotificationChannel ch : channels) {
24-
channelList[i++] = notificationChannelToWrapper(ch);
25-
}
26-
27-
return channelList;
28-
}
2915
}

0 commit comments

Comments
 (0)