Skip to content

Commit ebd7f3f

Browse files
Refactor: Simplify notification permission request logic
- Simplified the intent creation and launch for notification settings on Android 14+ (Upside Down Cake). - Removed a `FIXME` comment and suppressed the deprecation warning for `startActivityAndCollapse` on Android Oreo and above, as it is still the intended behavior for that code path.
1 parent 267c0c6 commit ebd7f3f

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

app/src/main/kotlin/com/d4rk/musicsleeptimer/plus/services/SleepTileService.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,18 @@ class SleepTileService : TileService() {
6262
private fun requestNotificationsPermission() {
6363
when {
6464
SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE -> {
65-
val intent = Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS).apply {
65+
startActivity(Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS).apply {
6666
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
6767
putExtra(Settings.EXTRA_APP_PACKAGE, packageName)
68-
}
69-
startActivity(intent)
68+
})
7069
}
7170

7271
SDK_INT >= Build.VERSION_CODES.O -> {
72+
@Suppress("DEPRECATION")
7373
Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS).apply {
7474
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
7575
putExtra(Settings.EXTRA_APP_PACKAGE , packageName)
76-
}.let(::startActivityAndCollapse) // FIXME: 'fun startActivityAndCollapse(intent: Intent!): Unit' is deprecated. Deprecated in Java.
76+
}.let(::startActivityAndCollapse)
7777
}
7878

7979
else -> {
@@ -85,5 +85,4 @@ class SleepTileService : TileService() {
8585
}
8686
}
8787
}
88-
8988
}

0 commit comments

Comments
 (0)