don't crash when no sharing app is found

This commit is contained in:
johan12345
2026-01-21 21:24:40 +01:00
parent 4507912f97
commit ce4f7418ea
4 changed files with 13 additions and 3 deletions

View File

@@ -342,12 +342,20 @@ class MapsActivity : AppCompatActivity(),
}
}
fun shareUrl(url: String) {
fun shareUrl(url: String, rootView: View) {
val intent = Intent(Intent.ACTION_SEND).apply {
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, url)
}
startActivity(intent)
try {
startActivity(intent)
} catch (e: ActivityNotFoundException) {
Snackbar.make(
rootView,
R.string.no_share_app_found,
Snackbar.LENGTH_SHORT
).show()
}
}
override fun onPreferenceStartFragment(

View File

@@ -513,7 +513,7 @@ class MapFragment : Fragment(), OnMapReadyCallback, MenuProvider {
R.id.menu_share -> {
val charger = vm.charger.value?.data
if (charger != null && charger.url != null) {
(activity as? MapsActivity)?.shareUrl(charger.url)
(activity as? MapsActivity)?.shareUrl(charger.url, binding.root)
}
true
}

View File

@@ -6,6 +6,7 @@
<string name="no_maps_app_found">Bitte installiere eine Navigations-App</string>
<string name="no_browser_app_found">Bitte installiere einen Webbrowser</string>
<string name="no_email_app_found">Bitte installiere eine E-Mail-App</string>
<string name="no_share_app_found">Keine App zum Teilen gefunden</string>
<string name="address">Adresse</string>
<string name="operator">Betreiber</string>
<string name="network">Verbund</string>

View File

@@ -6,6 +6,7 @@
<string name="no_maps_app_found">Install a navigation app first</string>
<string name="no_browser_app_found">Install a web browser first</string>
<string name="no_email_app_found">Install an email app first</string>
<string name="no_share_app_found">Could not find an app to share with</string>
<string name="address">Address</string>
<string name="operator">Operator</string>
<string name="network">Network</string>