This question talks about checking if Google Maps is installed on the device and the answer works fine. In newer versions of Android, we can only disable the Google Maps app not uninstall it so the above answer does not completely work for me.
When I was testing my app in a phone with Google Play services 9.2.x installed, it does not work when Google Maps app is disabled which is weird because it works fine without it in devices with Google Play services >= 9.4.x.
Is there a way to check if Google Maps app is disabled or not? (Please note that app is still installed just disabled.)
You can check this by using the package name as follows
String packageName = "com.google.android.gms.maps";
int flag = 0;
ApplicationInfo appInfo = getActivity().getPackageManager().getApplicationInfo(packageName,flag);
boolean isAppDisabled = appInfo.enabled;
Read here for more details. You can also set different flag constant based on your requirement as described in the documentation link.
Try this, for example, to display a map of San Francisco, you can use the following code:
Uri gmmIntentUri = Uri.parse("geo:37.7749,-122.4194");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
and now comes the important part:
if (mapIntent.resolveActivity(getPackageManager()) != null) {
startActivity(mapIntent);
}
As you can see, if is NOT null start that activity. Of course you can include an ELSE statement with a message for the user to announce him that Google Maps is not installed on his/her device.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With