Advertisement
yungKKKK

Notifications ext

Sep 25th, 2023 (edited)
1,133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.78 KB | None | 0 0
  1. val Context.isNotificationsEnabled: Boolean
  2.     get() = NotificationManagerCompat.from(this).areNotificationsEnabled()
  3.  
  4. /**
  5.  * The method opens system setting activity at app's notifications page.
  6.  *
  7.  * @param[channel]Name of notification's chanel
  8.  *
  9.  */
  10. @RequiresApi(Build.VERSION_CODES.O)
  11. fun Context.openNotificationSettings(
  12.     channel: String? = null,
  13. ) {
  14.     val intent = Intent().apply {
  15.         addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
  16.         channel?.let {
  17.             action = Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS
  18.             putExtra(Settings.EXTRA_CHANNEL_ID, channel)
  19.         } ?: run {
  20.             action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
  21.         }
  22.     }
  23.     intent.putExtra(Settings.EXTRA_APP_PACKAGE, packageName)
  24.     startActivity(intent)
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement