In Android, I am trying to open a google maps app with navigation from one location to another. At the same time, I have an offline map downloaded on my android device through Google Maps Apps and trying to redirect from one location to another programmatically using Java or kotlin. In contrast, the device doesn't have an internet connection. I have tried every possible solution for it but it's not working properly in Android 12 when the device is offline.
I have tried it through Intent but it's not working when the device doesn't have an internet connection.
fun openGoogleMapsNavigationFromAToB(context: Context,
originLatitude : Double,
originLongitude : Double,
destinationLatitude : Double,
destinationLongitude : Double)
{
val googleMapsUrl = "https://www.google.com/maps/dir/?api=1&" +
"origin=$originLatitude," +
"$originLongitude&" +
"destination=$destinationLatitude," +
"$destinationLongitude"
val uri = Uri.parse(googleMapsUrl)
val googleMapsPackage = "com.google.android.apps.maps"
val intent = Intent(Intent.ACTION_VIEW, uri).apply {
setPackage(googleMapsPackage)
}
context.startActivity(intent)
}
}