Skip to content

Commit 6aeede2

Browse files
committed
UiSettingsFragment: avoid crash when APP_OPEN_BY_DEFAULT_SETTINGS is not supported
1 parent 9125ff1 commit 6aeede2

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

app/src/main/java/net/vonforst/evmap/fragment/preference/UiSettingsFragment.kt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
package net.vonforst.evmap.fragment.preference
22

3+
import android.content.ActivityNotFoundException
34
import android.content.Intent
45
import android.content.SharedPreferences
5-
import android.net.Uri
66
import android.os.Build
77
import android.os.Bundle
88
import android.provider.Settings
9+
import android.util.Log
10+
import androidx.core.net.toUri
911
import androidx.preference.CheckBoxPreference
1012
import androidx.preference.ListPreference
1113
import androidx.preference.Preference
1214
import com.github.erfansn.localeconfigx.configuredLocales
15+
import com.google.android.material.snackbar.Snackbar
1316
import net.vonforst.evmap.R
1417
import net.vonforst.evmap.isAppInstalled
1518
import net.vonforst.evmap.ui.getAppLocale
@@ -83,9 +86,23 @@ class UiSettingsFragment : BaseSettingsFragment() {
8386
val context = context ?: return false
8487
val intent = Intent(
8588
Settings.ACTION_APP_OPEN_BY_DEFAULT_SETTINGS,
86-
Uri.parse("package:${context.packageName}")
89+
"package:${context.packageName}".toUri()
8790
)
88-
context.startActivity(intent)
91+
try {
92+
context.startActivity(intent)
93+
} catch (_: ActivityNotFoundException) {
94+
view?.let { v ->
95+
Snackbar.make(
96+
v,
97+
R.string.system_setting_not_supported,
98+
Snackbar.LENGTH_SHORT
99+
).show()
100+
}
101+
Log.e(
102+
"UiSettingsFragment",
103+
"Settings.ACTION_APP_OPEN_BY_DEFAULT_SETTINGS activity not found"
104+
)
105+
}
89106
}
90107
return true
91108
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<string name="no_browser_app_found">Bitte installiere einen Webbrowser</string>
88
<string name="no_email_app_found">Bitte installiere eine E-Mail-App</string>
99
<string name="no_share_app_found">Keine App zum Teilen gefunden</string>
10+
<string name="system_setting_not_supported">Diese Einstellung wird von deinem System nicht unterstützt</string>
1011
<string name="address">Adresse</string>
1112
<string name="operator">Betreiber</string>
1213
<string name="network">Verbund</string>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<string name="no_browser_app_found">Install a web browser first</string>
88
<string name="no_email_app_found">Install an email app first</string>
99
<string name="no_share_app_found">Could not find an app to share with</string>
10+
<string name="system_setting_not_supported">Your system does not support this setting</string>
1011
<string name="address">Address</string>
1112
<string name="operator">Operator</string>
1213
<string name="network">Network</string>

0 commit comments

Comments
 (0)