Java Code Examples for android.app.NotificationManager#deleteNotificationChannel()
The following examples show how to use
android.app.NotificationManager#deleteNotificationChannel() .
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: NotificationUtils.java From your-local-weather with GNU General Public License v3.0 | 7 votes |
public static void checkAndCreateNotificationChannel(Context context) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O) { return; } NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationChannel notificationChannel = notificationManager.getNotificationChannel("yourLocalWeather"); boolean createNotification = notificationChannel == null; if (!createNotification && ((notificationChannel.getImportance() == NotificationManager.IMPORTANCE_LOW) || (AppPreference.isVibrateEnabled(context) && (notificationChannel.getVibrationPattern() == null)))) { notificationManager.deleteNotificationChannel("yourLocalWeather"); createNotification = true; } if (createNotification) { NotificationChannel channel = new NotificationChannel("yourLocalWeather", context.getString(R.string.notification_channel_name), NotificationManager.IMPORTANCE_DEFAULT); channel.setDescription(context.getString(R.string.notification_channel_description)); channel.setVibrationPattern(isVibrateEnabled(context)); channel.enableVibration(AppPreference.isVibrateEnabled(context)); channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); channel.setSound(null, null); notificationManager.createNotificationChannel(channel); } }
Example 2
Source File: MaintenanceNotificationChannel.java From Hentoid with Apache License 2.0 | 6 votes |
public static void init(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { String name = "Technical maintenance"; int importance = NotificationManager.IMPORTANCE_DEFAULT; NotificationChannel channel = new NotificationChannel(ID, name, importance); channel.setSound(null, null); channel.setVibrationPattern(null); NotificationManager notificationManager = context.getSystemService(NotificationManager.class); // Mandatory; it is not possible to change the sound of an existing channel after its initial creation Objects.requireNonNull(notificationManager, "notificationManager must not be null"); notificationManager.deleteNotificationChannel(ID_OLD); notificationManager.createNotificationChannel(channel); } }
Example 3
Source File: NotificationChannels.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
@TargetApi(26) private static void onUpgrade(@NonNull NotificationManager notificationManager, int oldVersion, int newVersion) { Log.i(TAG, "Upgrading channels from " + oldVersion + " to " + newVersion); if (oldVersion < Version.MESSAGES_CATEGORY) { notificationManager.deleteNotificationChannel("messages"); notificationManager.deleteNotificationChannel("calls"); notificationManager.deleteNotificationChannel("locked_status"); notificationManager.deleteNotificationChannel("backups"); notificationManager.deleteNotificationChannel("other"); } if (oldVersion < Version.CALLS_PRIORITY_BUMP) { notificationManager.deleteNotificationChannel("calls_v2"); } }
Example 4
Source File: SdlRouterService.java From sdl_java_suite with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void exitForeground(){ synchronized (NOTIFICATION_LOCK) { if (isForeground && !isPrimaryTransportConnected()) { //Ensure that the service is in the foreground and no longer connected to a transport DebugTool.logInfo("SdlRouterService to exit foreground"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { this.stopForeground(Service.STOP_FOREGROUND_DETACH); }else{ stopForeground(false); } NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); if (notificationManager!= null){ try { notificationManager.cancelAll(); if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !getBooleanPref(KEY_AVOID_NOTIFICATION_CHANNEL_DELETE,false)) { notificationManager.deleteNotificationChannel(SDL_NOTIFICATION_CHANNEL_ID); } } catch (Exception e) { DebugTool.logError("Issue when removing notification and channel", e); } } isForeground = false; } } }
Example 5
Source File: UpdateNotificationChannel.java From Hentoid with Apache License 2.0 | 6 votes |
public static void init(@NonNull Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { String name = "Updates"; int importance = NotificationManager.IMPORTANCE_DEFAULT; NotificationChannel channel = new NotificationChannel(ID, name, importance); channel.setSound(null, null); channel.setVibrationPattern(null); NotificationManager notificationManager = context.getSystemService(NotificationManager.class); // Mandatory; it is not possible to change the sound of an existing channel after its initial creation Objects.requireNonNull(notificationManager, "notificationManager must not be null"); notificationManager.deleteNotificationChannel(ID_OLD); notificationManager.deleteNotificationChannel(ID_OLD2); notificationManager.createNotificationChannel(channel); } }
Example 6
Source File: LeanplumNotificationChannel.java From Leanplum-Android-SDK with Apache License 2.0 | 6 votes |
/** * Delete push notification channel. * * @param context The application context. * @param channelId The id of the channel. */ private static void deleteNotificationChannel(Context context, String channelId) { if (context == null) { return; } if (BuildUtil.isNotificationChannelSupported(context)) { try { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (notificationManager == null) { Log.e("Notification manager is null"); return; } notificationManager.deleteNotificationChannel(channelId); } catch (Throwable t) { Util.handleException(t); } } }
Example 7
Source File: DownloadNotificationChannel.java From Hentoid with Apache License 2.0 | 6 votes |
public static void init(@NonNull Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { String name = "Book downloads"; int importance = NotificationManager.IMPORTANCE_DEFAULT; NotificationChannel channel = new NotificationChannel(ID, name, importance); channel.setSound(null, null); channel.setVibrationPattern(null); NotificationManager notificationManager = context.getSystemService(NotificationManager.class); // Mandatory; it is not possible to change the sound of an existing channel after its initial creation Objects.requireNonNull(notificationManager, "notificationManager must not be null"); notificationManager.deleteNotificationChannel(ID_OLD); notificationManager.createNotificationChannel(channel); } }
Example 8
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 9
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 10
Source File: FIRMessagingModule.java From react-native-fcm with MIT License | 5 votes |
@ReactMethod public void deleteNotificationChannel(String id, Promise promise) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationManager mngr = (NotificationManager) getReactApplicationContext().getSystemService(NOTIFICATION_SERVICE); mngr.deleteNotificationChannel(id); } promise.resolve(null); }
Example 11
Source File: NotificationRulesAdapter.java From revolution-irc with GNU General Public License v3.0 | 5 votes |
@Override public void onSwiped(RecyclerView.ViewHolder viewHolder, int i) { int position = viewHolder.getAdapterPosition(); int index = position - getUserRulesStartIndex(); NotificationRule rule = mRules.remove(index); notifyItemRemoved(position); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationManager mgr = (NotificationManager) viewHolder.itemView.getContext() .getSystemService(Context.NOTIFICATION_SERVICE); mgr.deleteNotificationChannel(rule.settings.notificationChannelId); } if (mRules.size() == 0) notifyItemInserted(getUserRulesStartIndex() + 1); // the tip Snackbar.make(viewHolder.itemView, R.string.notification_custom_rule_deleted, Snackbar.LENGTH_SHORT) .setAction(R.string.action_undo, (View v) -> { int newIndex = Math.min(index, mRules.size()); mRules.add(newIndex, rule); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) ChannelNotificationManager.createChannel( viewHolder.itemView.getContext(), rule); if (mRules.size() == 1) notifyItemRemoved(getUserRulesStartIndex() + 1); // the tip notifyItemInserted(newIndex + getUserRulesStartIndex()); mHasChanges = true; }) .show(); mHasChanges = true; }
Example 12
Source File: ChannelCreator.java From Synapse with Apache License 2.0 | 5 votes |
@RequiresApi(api = Build.VERSION_CODES.O) public static void createChannel(@NonNull Context context) { Precondition.checkNotNull(context); final NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT); channel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PUBLIC); final NotificationManager manager = getManager(context); manager.deleteNotificationChannel(CHANNEL_ID); manager.createNotificationChannel(channel); }
Example 13
Source File: AndroidNotification.java From QtAndroidTools with MIT License | 5 votes |
public void deleteNotificationChannel() { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationManager Manager = mActivityInstance.getSystemService(NotificationManager.class); Manager.deleteNotificationChannel(NOTIFICATION_CHANNEL_ID); } }
Example 14
Source File: SongBroadCast.java From YTPlayer with GNU General Public License v3.0 | 5 votes |
public void disableContext(Context context) { NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(context); notificationManagerCompat.cancel(1); if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.deleteNotificationChannel("channel_01"); } Process.killProcess(Process.myPid()); }
Example 15
Source File: MusicService.java From YTPlayer with GNU General Public License v3.0 | 5 votes |
@Override public void onDestroy() { if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O) { NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.deleteNotificationChannel("channel_01"); notificationManager.deleteNotificationChannel("channel_02"); } isEqualizerSet = false; if (PlayerActivity2.activity!=null) { PlayerActivity2.activity.finish(); } try { bottom_player.setVisibility(View.GONE); adView.setVisibility(View.GONE); onClear(); MainActivity.activity.findViewById(R.id.adViewLayout_add) .setVisibility(View.GONE); }catch (Exception ignored){ } notificationManagerCompat.cancel(1); try { if (mEqualizer!=null) mEqualizer.release(); if (bassBoost!=null) bassBoost.release(); if (loudnessEnhancer!=null) loudnessEnhancer.release(); if (virtualizer!=null) virtualizer.release(); player.stop(); player.release(); }catch (Exception e) { e.printStackTrace(); } wakeLock.release(); activity = null; super.onDestroy(); }
Example 16
Source File: NotificationChannels.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
@TargetApi(26) private static void onCreate(@NonNull Context context, @NonNull NotificationManager notificationManager) { NotificationChannelGroup messagesGroup = new NotificationChannelGroup(CATEGORY_MESSAGES, context.getResources().getString(R.string.NotificationChannel_group_messages)); notificationManager.createNotificationChannelGroup(messagesGroup); NotificationChannel messages = new NotificationChannel(getMessagesChannel(context), context.getString(R.string.NotificationChannel_messages), NotificationManager.IMPORTANCE_HIGH); NotificationChannel calls = new NotificationChannel(CALLS, context.getString(R.string.NotificationChannel_calls), NotificationManager.IMPORTANCE_HIGH); NotificationChannel failures = new NotificationChannel(FAILURES, context.getString(R.string.NotificationChannel_failures), NotificationManager.IMPORTANCE_HIGH); NotificationChannel backups = new NotificationChannel(BACKUPS, context.getString(R.string.NotificationChannel_backups), NotificationManager.IMPORTANCE_LOW); NotificationChannel lockedStatus = new NotificationChannel(LOCKED_STATUS, context.getString(R.string.NotificationChannel_locked_status), NotificationManager.IMPORTANCE_LOW); NotificationChannel other = new NotificationChannel(OTHER, context.getString(R.string.NotificationChannel_other), NotificationManager.IMPORTANCE_LOW); messages.setGroup(CATEGORY_MESSAGES); messages.enableVibration(TextSecurePreferences.isNotificationVibrateEnabled(context)); messages.setSound(TextSecurePreferences.getNotificationRingtone(context), getRingtoneAudioAttributes()); setLedPreference(messages, TextSecurePreferences.getNotificationLedColor(context)); calls.setShowBadge(false); backups.setShowBadge(false); lockedStatus.setShowBadge(false); other.setShowBadge(false); notificationManager.createNotificationChannels(Arrays.asList(messages, calls, failures, backups, lockedStatus, other)); if (BuildConfig.AUTOMATIC_UPDATES) { NotificationChannel appUpdates = new NotificationChannel(APP_UPDATES, context.getString(R.string.NotificationChannel_app_updates), NotificationManager.IMPORTANCE_HIGH); notificationManager.createNotificationChannel(appUpdates); } else { notificationManager.deleteNotificationChannel(APP_UPDATES); } }
Example 17
Source File: NotificationChannels.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
/** * Deletes the channel generated for the provided recipient. Safe to call even if there was never * a channel made for that recipient. */ public static synchronized void deleteChannelFor(@NonNull Context context, @NonNull Recipient recipient) { if (!supported()) { return; } NotificationManager notificationManager = ServiceUtil.getNotificationManager(context); String channel = recipient.getNotificationChannel(); if (channel != null) { Log.i(TAG, "Deleting channel"); notificationManager.deleteNotificationChannel(channel); } }
Example 18
Source File: ProxyService.java From igniter with GNU General Public License v3.0 | 4 votes |
private void destroyNotificationChannel(String channelId) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationManager notificationManager = getSystemService(NotificationManager.class); notificationManager.deleteNotificationChannel(channelId); } }
Example 19
Source File: TupleFolderEx.java From FairEmail with GNU General Public License v3.0 | 4 votes |
@RequiresApi(api = Build.VERSION_CODES.O) void deleteNotificationChannel(Context context) { NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.deleteNotificationChannel(getNotificationChannelId(id)); }
Example 20
Source File: EntityAccount.java From FairEmail with GNU General Public License v3.0 | 4 votes |
@RequiresApi(api = Build.VERSION_CODES.O) void deleteNotificationChannel(Context context) { NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.deleteNotificationChannel(getNotificationChannelId(id)); }