Skip to content

Commit 6f82494

Browse files
committed
Merge deleteNotificationChannel
1 parent 4968e9a commit 6f82494

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -258,24 +258,27 @@ protected NotificationChannelWrapper getNotificationChannel(String id) {
258258
return UnityNotificationManager.getNotificationChannel(mContext, id);
259259
}
260260

261-
// Delete a notification channel by id.
262-
// This function will only be called for devices which are low than Android O.
263261
public void deleteNotificationChannel(String id) {
264-
SharedPreferences prefs = mContext.getSharedPreferences(NOTIFICATION_CHANNELS_SHARED_PREFS, Context.MODE_PRIVATE);
265-
Set<String> channelIds = new HashSet<String>(prefs.getStringSet(NOTIFICATION_CHANNELS_SHARED_PREFS_KEY, new HashSet<String>()));
262+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
263+
getNotificationManager().deleteNotificationChannel(id);
264+
} else {
265+
SharedPreferences prefs = mContext.getSharedPreferences(NOTIFICATION_CHANNELS_SHARED_PREFS, Context.MODE_PRIVATE);
266+
Set<String> channelIds = prefs.getStringSet(NOTIFICATION_CHANNELS_SHARED_PREFS_KEY, new HashSet());
266267

267-
if (!channelIds.contains(id))
268-
return;
268+
if (!channelIds.contains(id))
269+
return;
269270

270-
// Remove from the notification channel ids SharedPreferences.
271-
channelIds.remove(id);
272-
SharedPreferences.Editor editor = prefs.edit().clear();
273-
editor.putStringSet(NOTIFICATION_CHANNELS_SHARED_PREFS_KEY, channelIds);
274-
editor.apply();
271+
// Remove from the notification channel ids SharedPreferences.
272+
channelIds = new HashSet(channelIds);
273+
channelIds.remove(id);
274+
SharedPreferences.Editor editor = prefs.edit().clear();
275+
editor.putStringSet(NOTIFICATION_CHANNELS_SHARED_PREFS_KEY, channelIds);
276+
editor.apply();
275277

276-
// Delete the notification channel SharedPreferences.
277-
SharedPreferences channelPrefs = mContext.getSharedPreferences(getSharedPrefsNameByChannelId(id), Context.MODE_PRIVATE);
278-
channelPrefs.edit().clear().apply();
278+
// Delete the notification channel SharedPreferences.
279+
SharedPreferences channelPrefs = mContext.getSharedPreferences(getSharedPrefsNameByChannelId(id), Context.MODE_PRIVATE);
280+
channelPrefs.edit().clear().apply();
281+
}
279282
}
280283

281284
// Get all notification channels.

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ public UnityNotificationManagerOreo(Context context, Activity activity) {
1313
super(context, activity);
1414
}
1515

16-
@Override
17-
public void deleteNotificationChannel(String id) {
18-
assert Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
19-
20-
getNotificationManager().deleteNotificationChannel(id);
21-
}
22-
2316
@Override
2417
public NotificationChannelWrapper[] getNotificationChannels() {
2518
assert Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;

0 commit comments

Comments
 (0)