diff --git a/app/src/main/java/org/mozilla/fenix/ext/Activity.kt b/app/src/main/java/org/mozilla/fenix/ext/Activity.kt index 6626f36b5c..b78fad924a 100644 --- a/app/src/main/java/org/mozilla/fenix/ext/Activity.kt +++ b/app/src/main/java/org/mozilla/fenix/ext/Activity.kt @@ -156,23 +156,6 @@ private fun Activity.openDefaultBrowserSumoPage( } } -/** - * Checks for the presence of an activity before starting it. In case it's not present, - * [onActivityNotPresent] is invoked, preventing ActivityNotFoundException from being thrown. - * This is useful when navigating to external activities like device permission settings, - * notification settings, default app settings, etc. - * - * @param intent The Intent of the activity to resolve and start. - * @param onActivityNotPresent Invoked when the activity to handle the intent is not present. - */ -inline fun Activity.startExternalActivitySafe(intent: Intent, onActivityNotPresent: () -> Unit) { - if (intent.resolveActivity(packageManager) != null) { - startActivity(intent) - } else { - onActivityNotPresent() - } -} - /** * Sets the icon for the back (up) navigation button. * @param icon The resource id of the icon. diff --git a/app/src/main/java/org/mozilla/fenix/ext/Context.kt b/app/src/main/java/org/mozilla/fenix/ext/Context.kt index 8afb8b7273..edfc37ff12 100644 --- a/app/src/main/java/org/mozilla/fenix/ext/Context.kt +++ b/app/src/main/java/org/mozilla/fenix/ext/Context.kt @@ -88,9 +88,13 @@ val Context.accessibilityManager: AccessibilityManager get() = getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager /** - * Used to navigate to system notifications settings for app + * Used to navigate to system notifications settings for app. + * + * @param onError Invoked when the activity described by the intent is not present on the device. */ -fun Context.navigateToNotificationsSettings() { +fun Context.navigateToNotificationsSettings( + onError: () -> Unit, +) { val intent = Intent() intent.let { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { @@ -102,7 +106,24 @@ fun Context.navigateToNotificationsSettings() { it.putExtra("app_uid", this.applicationInfo.uid) } } - startActivity(intent) + startExternalActivitySafe(intent, onError) +} + +/** + * Checks for the presence of an activity before starting it. In case it's not present, + * [onActivityNotPresent] is invoked, preventing ActivityNotFoundException from being thrown. + * This is useful when navigating to external activities like device permission settings, + * notification settings, default app settings, etc. + * + * @param intent The Intent of the activity to resolve and start. + * @param onActivityNotPresent Invoked when the activity to handle the intent is not present. + */ +inline fun Context.startExternalActivitySafe(intent: Intent, onActivityNotPresent: () -> Unit) { + if (intent.resolveActivity(packageManager) != null) { + startActivity(intent) + } else { + onActivityNotPresent() + } } /** diff --git a/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt index a13938bc03..6615b907c2 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt @@ -354,7 +354,7 @@ class SettingsFragment : PreferenceFragmentCompat() { SettingsFragmentDirections.actionSettingsFragmentToDeleteBrowsingDataOnQuitFragment() } resources.getString(R.string.pref_key_notifications) -> { - context?.navigateToNotificationsSettings() + context?.navigateToNotificationsSettings {} null } resources.getString(R.string.pref_key_customize) -> {