Protection against ActivityNotFoundException.
This commit is contained in:
parent
8b161bf72c
commit
7a9a7c4af5
1 changed files with 12 additions and 5 deletions
|
|
@ -71,7 +71,10 @@ fun Context.copyToClipboard(
|
||||||
* Shows notification settings for the current app.
|
* Shows notification settings for the current app.
|
||||||
* In android O will directly opens the notification settings, in lower version it will show the App settings
|
* In android O will directly opens the notification settings, in lower version it will show the App settings
|
||||||
*/
|
*/
|
||||||
fun Context.startNotificationSettingsIntent(activityResultLauncher: ActivityResultLauncher<Intent>? = null) {
|
fun Context.startNotificationSettingsIntent(
|
||||||
|
activityResultLauncher: ActivityResultLauncher<Intent>? = null,
|
||||||
|
noActivityFoundMessage: String = getString(R.string.error_no_compatible_app_found),
|
||||||
|
) {
|
||||||
val intent = Intent()
|
val intent = Intent()
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
intent.action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
|
intent.action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
|
||||||
|
|
@ -85,10 +88,14 @@ fun Context.startNotificationSettingsIntent(activityResultLauncher: ActivityResu
|
||||||
intent.data = Uri.fromParts("package", packageName, null)
|
intent.data = Uri.fromParts("package", packageName, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activityResultLauncher != null) {
|
try {
|
||||||
activityResultLauncher.launch(intent)
|
if (activityResultLauncher != null) {
|
||||||
} else {
|
activityResultLauncher.launch(intent)
|
||||||
startActivity(intent)
|
} else {
|
||||||
|
startActivity(intent)
|
||||||
|
}
|
||||||
|
} catch (activityNotFoundException: ActivityNotFoundException) {
|
||||||
|
toast(noActivityFoundMessage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue