Skip to content

Commit 80dc827

Browse files
committed
Protection against ActivityNotFoundException.
1 parent b6fd46e commit 80dc827

File tree

1 file changed

+12
-5
lines changed
  • libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/system

1 file changed

+12
-5
lines changed

libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/system/SystemUtils.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ fun Context.copyToClipboard(
7171
* Shows notification settings for the current app.
7272
* In android O will directly opens the notification settings, in lower version it will show the App settings
7373
*/
74-
fun Context.startNotificationSettingsIntent(activityResultLauncher: ActivityResultLauncher<Intent>? = null) {
74+
fun Context.startNotificationSettingsIntent(
75+
activityResultLauncher: ActivityResultLauncher<Intent>? = null,
76+
noActivityFoundMessage: String = getString(R.string.error_no_compatible_app_found),
77+
) {
7578
val intent = Intent()
7679
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
7780
intent.action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
@@ -85,10 +88,14 @@ fun Context.startNotificationSettingsIntent(activityResultLauncher: ActivityResu
8588
intent.data = Uri.fromParts("package", packageName, null)
8689
}
8790

88-
if (activityResultLauncher != null) {
89-
activityResultLauncher.launch(intent)
90-
} else {
91-
startActivity(intent)
91+
try {
92+
if (activityResultLauncher != null) {
93+
activityResultLauncher.launch(intent)
94+
} else {
95+
startActivity(intent)
96+
}
97+
} catch (activityNotFoundException: ActivityNotFoundException) {
98+
toast(noActivityFoundMessage)
9299
}
93100
}
94101

0 commit comments

Comments
 (0)