Skip to content

Instantly share code, notes, and snippets.

@libliboom
Created April 27, 2021 06:48
Show Gist options
  • Save libliboom/c6e3f761e9956b3860552fb86b6fca94 to your computer and use it in GitHub Desktop.
Save libliboom/c6e3f761e9956b3860552fb86b6fca94 to your computer and use it in GitHub Desktop.
fun Context.createNotificationSettingsIntent() =
when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O -> {
Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS).apply {
putExtra(Settings.EXTRA_APP_PACKAGE, packageName)
}
}
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP -> {
Intent().apply {
action = "android.settings.APP_NOTIFICATION_SETTINGS"
putExtra("app_package", packageName)
putExtra("app_uid", applicationInfo.uid)
}
}
else -> {
Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply {
data = Uri.parse("package:$packageName")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment