如何检查gmail是启用还是禁用

时间:2014-03-04 00:21:25

标签: android

我正在检查设备上是否安装了gmail应用:

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) {
}

但我不知道如何检查它是启用还是禁用。

1 个答案:

答案 0 :(得分:0)

您可以在启动应用之前使用Intent.resolveActivity。类似的东西:

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

要检查应用是否已启用,您可以使用PackageManager.getApplicationInfo

ApplicationInfo ai = getPackageManager().getApplicationInfo("com.google.android.gm", 0);
// ai.enabled will return `true` if it's enabled and `false` otherwise