Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val Context.isNotificationsEnabled: Boolean
- get() = NotificationManagerCompat.from(this).areNotificationsEnabled()
- /**
- * The method opens system setting activity at app's notifications page.
- *
- * @param[channel]Name of notification's chanel
- *
- */
- @RequiresApi(Build.VERSION_CODES.O)
- fun Context.openNotificationSettings(
- channel: String? = null,
- ) {
- val intent = Intent().apply {
- addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
- channel?.let {
- action = Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS
- putExtra(Settings.EXTRA_CHANNEL_ID, channel)
- } ?: run {
- action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
- }
- }
- intent.putExtra(Settings.EXTRA_APP_PACKAGE, packageName)
- startActivity(intent)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement