From 6b07ce012adb8047cbde7d8b1219c4c4a67bd2cc Mon Sep 17 00:00:00 2001 From: johan12345 Date: Thu, 15 May 2025 23:15:51 +0200 Subject: [PATCH] Rework showLocation function avoid opening within EVMap itself --- .../java/net/vonforst/evmap/MapsActivity.kt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/net/vonforst/evmap/MapsActivity.kt b/app/src/main/java/net/vonforst/evmap/MapsActivity.kt index dfd6ad4f..5103027e 100644 --- a/app/src/main/java/net/vonforst/evmap/MapsActivity.kt +++ b/app/src/main/java/net/vonforst/evmap/MapsActivity.kt @@ -257,9 +257,24 @@ class MapsActivity : AppCompatActivity(), Uri.encode(charger.name) })" ) - if (intent.resolveActivity(packageManager) != null) { + + val resolveInfo = + packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) + val pkg = + resolveInfo?.activityInfo?.packageName.takeIf { it != "android" && it != packageName } + if (pkg == null) { + // There is no default maps app or EVMap itself is the current default, fall back to app chooser + val chooserIntent = Intent.createChooser(intent, null).apply { + putExtra(Intent.EXTRA_EXCLUDE_COMPONENTS, arrayOf(componentName)) + } + startActivity(chooserIntent) + return + } + intent.setPackage(pkg) + + try { startActivity(intent) - } else { + } catch (e: ActivityNotFoundException) { Snackbar.make( rootView, R.string.no_maps_app_found,