Rio Marie A. Callos
Rio Marie A. Callos

Reputation: 194

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

Upvotes: 4

Views: 4595

Answers (3)

CoolMind
CoolMind

Reputation: 28865

Connecting non-working solution of @GauravSarma and string from @CristianBabarusi I also got non-working solution. It returns true on API 19 emulator without Google Play Services.

private fun isMapsAvailable() : Boolean {
    val packageName = "com.google.android.apps.maps"
    val flag = 0
    return try {
        val appInfo = activity?.packageManager?.getApplicationInfo(packageName, flag)
        appInfo?.enabled == true
    } catch (e: PackageManager.NameNotFoundException) {
        false
    }
}

Upvotes: 0

Cristian Babarusi
Cristian Babarusi

Reputation: 1505

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.

Upvotes: 1

Gaurav Sarma
Gaurav Sarma

Reputation: 2297

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.

Upvotes: 7

Related Questions