Question

I'm checking if gmail app is installed on the device this way:

public boolean isGmailInstalled(String uri) {

PackageManager pm = getPackageManager();
boolean app_installed = false;

try {           
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
} catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed;
}

OnClick

boolean installed = isGmailInstalled("com.google.android.gm");

if (installed) {
}

But I don't know how to check if it's enabled or disabled.

Was it helpful?

Solution

You can use Intent.resolveActivity before launching the app. Something like:

    if (yourIntent.resolveActivity(getPackageManager()) != null) {
        startActivity(yourIntent);
    }

To check if the app is enabled, you can use PackageManager.getApplicationInfo.

ApplicationInfo ai = getPackageManager().getApplicationInfo("com.google.android.gm", 0);
// ai.enabled will return `true` if it's enabled and `false` otherwise
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top