[fenix] Closes 28414: NotificationManagerCompat extension to safely check if notifications are enabled
parent
506cf152fb
commit
d760e57572
@ -0,0 +1,20 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.ext
|
||||
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
|
||||
/**
|
||||
* Returns whether notifications are enabled, catches any exception that was thrown from
|
||||
* [NotificationManagerCompat.areNotificationsEnabled] and returns false.
|
||||
*/
|
||||
@Suppress("TooGenericExceptionCaught")
|
||||
fun NotificationManagerCompat.areNotificationsEnabledSafe(): Boolean {
|
||||
return try {
|
||||
areNotificationsEnabled()
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue