Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps Android API V2 Check if Google Maps app is disabled

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.)

like image 841
Rio Marie A. Callos Avatar asked Feb 06 '23 04:02

Rio Marie A. Callos


2 Answers

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.

like image 196
Gaurav Sarma Avatar answered Feb 08 '23 18:02

Gaurav Sarma


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.

like image 28
Cristian Babarusi Avatar answered Feb 08 '23 19:02

Cristian Babarusi