Unable to open google map in android 13, its working fine on all other android versions though. Here is the code.
fun openNavigation(activity: Activity, latLng: LatLng) {
try {
val packageName = StringConstants.MAPS_PACKAGE_NAME
val query = String.format(
activity.getString(R.string.maps_navigation_query),
latLng.latitude,
latLng.longitude
)
val intent = activity.packageManager.getLaunchIntentForPackage(packageName)
intent?.action = Intent.ACTION_VIEW
intent?.data = Uri.parse(query)
activity.startActivity(intent)
} catch (e: Exception) {
e.printStackTrace()
}
}
Logcat:
W/System.err: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.google.android.apps.maps/com.google.android.maps.MapsActivity}; have you declared this activity in your AndroidManifest.xml, or does your intent not match its declared <intent-filter>?
CodePudding user response:
I was using the package manager to create intent for me, but i replace it with the below code and it started working fine android 13 as well.
activity.startActivity(
Intent(Intent.ACTION_VIEW, Uri.parse(query)).apply {
setPackage(StringConstants.MAPS_PACKAGE_NAME)
}
)
Basically, I created the Intent object myself.