When you want your app to start a map activity, you can use an
implicit intent in Android development.
Many examples found online show how to do this, by using
Intent.ACTION_VIEW
. However, most of them show the approach with a specific URI, letting
the user open a map app with the specified coordinates of longitude
and latitude.
But what if you want to let the user just launch (open) a map activity in another app on the device,
without specifying any location?
The solution is quite straightforward: just leave the coordinates
blank.
A code example in Kotlin:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun openMap() { | |
val intent = Intent(Intent.ACTION_VIEW).apply { | |
data = Uri.parse("geo:,") | |
} | |
try { | |
startActivity(intent) | |
} catch (ex: ActivityNotFoundException) { | |
// Handle exception(s) here | |
} | |
} |