Java Code Examples for android.app.NotificationManager#getNotificationChannels()
The following examples show how to use
android.app.NotificationManager#getNotificationChannels() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NotificationChannels.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
@TargetApi(26) @WorkerThread public static synchronized void ensureCustomChannelConsistency(@NonNull Context context) { if (!supported()) { return; } Log.d(TAG, "ensureCustomChannelConsistency()"); NotificationManager notificationManager = ServiceUtil.getNotificationManager(context); RecipientDatabase db = DatabaseFactory.getRecipientDatabase(context); List<Recipient> customRecipients = new ArrayList<>(); Set<String> customChannelIds = new HashSet<>(); try (RecipientDatabase.RecipientReader reader = db.getRecipientsWithNotificationChannels()) { Recipient recipient; while ((recipient = reader.getNext()) != null) { customRecipients.add(recipient); customChannelIds.add(recipient.getNotificationChannel()); } } Set<String> existingChannelIds = Stream.of(notificationManager.getNotificationChannels()).map(NotificationChannel::getId).collect(Collectors.toSet()); for (NotificationChannel existingChannel : notificationManager.getNotificationChannels()) { if (existingChannel.getId().startsWith(CONTACT_PREFIX) && !customChannelIds.contains(existingChannel.getId())) { Log.i(TAG, "Consistency: Deleting channel '"+ existingChannel.getId() + "' because the DB has no record of it."); notificationManager.deleteNotificationChannel(existingChannel.getId()); } else if (existingChannel.getId().startsWith(MESSAGES_PREFIX) && !existingChannel.getId().equals(getMessagesChannel(context))) { Log.i(TAG, "Consistency: Deleting channel '"+ existingChannel.getId() + "' because it's out of date."); notificationManager.deleteNotificationChannel(existingChannel.getId()); } } for (Recipient customRecipient : customRecipients) { if (!existingChannelIds.contains(customRecipient.getNotificationChannel())) { Log.i(TAG, "Consistency: Removing custom channel '"+ customRecipient.getNotificationChannel() + "' because the system doesn't have it."); db.setNotificationChannel(customRecipient.getId(), null); } } }
Example 2
Source File: LeanplumNotificationChannel.java From Leanplum-Android-SDK with Apache License 2.0 | 5 votes |
/** * Get list of NotificationChannel. * * @param context The application context. * @return Returns all notification channels belonging to the calling package. */ static List<NotificationChannel> getNotificationChannels(Context context) { if (BuildUtil.isNotificationChannelSupported(context)) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (notificationManager == null) { Log.e("Notification manager is null"); return null; } return notificationManager.getNotificationChannels(); } return null; }
Example 3
Source File: PushTemplateHelper.java From Android-SDK with MIT License | 5 votes |
static public void deleteNotificationChannel( Context context ) { if( android.os.Build.VERSION.SDK_INT < 26 ) return; NotificationManager notificationManager = (NotificationManager) context.getSystemService( Context.NOTIFICATION_SERVICE ); List<NotificationChannel> notificationChannels = notificationManager.getNotificationChannels(); for (NotificationChannel notifChann : notificationChannels) notificationManager.deleteNotificationChannel( notifChann.getId() ); }
Example 4
Source File: PlaybackNotificationFactoryImpl.java From PainlessMusicPlayer with Apache License 2.0 | 4 votes |
@RequiresApi(Build.VERSION_CODES.O) private static boolean hasChannels(@NonNull final NotificationManager notificationManager) { final List<NotificationChannel> channels = notificationManager .getNotificationChannels(); return channels != null && !channels.isEmpty(); }