Skip to content

Commit dfa66f2

Browse files
Add full-screen intent permission setting for Android 14+
Shows a settings entry under Notifications that takes the user to the system full-screen intent permission page. Auto-hides once permission is granted. This is needed because the permission is not granted by default on Android 14+ and there is no natural in-flow moment to request it.
1 parent 31d6fc5 commit dfa66f2

4 files changed

Lines changed: 45 additions & 0 deletions

File tree

app-base/src/main/res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,10 @@
830830

831831
<string name="whitelist_settings_template">System setting %d</string>
832832

833+
<!--Permission settings-->
834+
<string name="pref_full_screen_notifications">Full-screen notifications</string>
835+
<string name="pref_full_screen_notifications_summary">Allow timer alerts to display over other apps</string>
836+
833837
<!--Account-->
834838
<string name="account_sign_out_confirmation">Sign out?</string>
835839
<string name="account_sign_out">Sign Out</string>

app-settings/src/main/java/xyz/aprildown/timer/app/settings/SettingsFragment.kt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package xyz.aprildown.timer.app.settings
22

33
import android.Manifest
4+
import android.app.NotificationManager
45
import android.content.Intent
56
import android.content.SharedPreferences
67
import android.os.Build
78
import android.os.Bundle
89
import android.provider.Settings
910
import androidx.activity.result.contract.ActivityResultContracts
11+
import androidx.core.content.getSystemService
1012
import androidx.core.net.toUri
1113
import androidx.navigation.fragment.NavHostFragment
1214
import androidx.preference.ListPreference
@@ -148,6 +150,26 @@ class SettingsFragment :
148150
)
149151
}
150152
}
153+
KEY_FULL_SCREEN_NOTIFICATIONS -> {
154+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
155+
val settingsIntent = Intent(
156+
Settings.ACTION_MANAGE_APP_USE_FULL_SCREEN_INTENT,
157+
"package:${context.packageName}".toUri()
158+
)
159+
startActivityOrNothing(
160+
settingsIntent.createChooserIntentIfDead(context),
161+
wrongMessageRes = RBase.string.no_action_found
162+
)
163+
} else {
164+
val settingsIntent = Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
165+
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
166+
.putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName)
167+
startActivityOrNothing(
168+
settingsIntent.createChooserIntentIfDead(context),
169+
wrongMessageRes = RBase.string.no_action_found
170+
)
171+
}
172+
}
151173
KEY_AUDIO_VOLUME -> {
152174
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
153175
startActivityOrNothing(Intent(Settings.Panel.ACTION_VOLUME))
@@ -222,6 +244,16 @@ class SettingsFragment :
222244

223245
findPreference<Preference>(KEY_NOTIF_SETTING)?.onPreferenceClickListener = this
224246

247+
findPreference<Preference>(KEY_FULL_SCREEN_NOTIFICATIONS)?.run {
248+
onPreferenceClickListener = this@SettingsFragment
249+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
250+
val nm = requireContext().getSystemService<NotificationManager>()
251+
isVisible = nm != null && !nm.canUseFullScreenIntent()
252+
} else {
253+
isVisible = false
254+
}
255+
}
256+
225257
findPreference<Preference>(KEY_AUDIO_VOLUME)?.run {
226258
onPreferenceClickListener = this@SettingsFragment
227259
isVisible = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
@@ -330,6 +362,7 @@ private const val KEY_PHONE_CALL = PreferenceData.KEY_PHONE_CALL
330362
private const val KEY_WEEK_START = PreferenceData.KEY_WEEK_START
331363

332364
private const val KEY_NOTIF_SETTING = "key_notif_setting"
365+
private const val KEY_FULL_SCREEN_NOTIFICATIONS = "key_full_screen_notifications"
333366

334367
private const val KEY_AUDIO_VOLUME = "key_audio_volume"
335368

app-settings/src/main/res/xml/pref_settings.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@
136136
app:key="key_media_style_notification"
137137
app:title="@string/pref_media_style_notification" />
138138

139+
<Preference
140+
app:icon="@drawable/settings_notifications"
141+
app:key="key_full_screen_notifications"
142+
app:persistent="false"
143+
app:singleLineTitle="false"
144+
app:title="@string/pref_full_screen_notifications"
145+
app:summary="@string/pref_full_screen_notifications_summary" />
146+
139147
</PreferenceCategory>
140148

141149
<PreferenceCategory app:title="@string/pref_category_title_audio">

gradlew

100644100755
File mode changed.

0 commit comments

Comments
 (0)