检查特定手机号码是否安装了whatsapp

时间:2016-06-27 10:30:16

标签: android whatsapp

如何检查用户是否安装了whatsapp ??? 我想要应用程序,就像我点击用户号码它应该显示消息是否该用户有whatsapp ... 请帮助我。我有联系人信息的列表视图,意思是姓名和号码。我想点击列表视图项目,检查该特定号码是否安装了whatsapp ????

2 个答案:

答案 0 :(得分:1)

使用packagemanager获取已安装的应用信息: 对于whatsapp包名称是com.whatsapp

boolean installed = appInstalledOrNot("com.whatsapp");  //the method returns boolean value here

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

答案 1 :(得分:1)

public static boolean isInstalled(String packageName) {
    if (StringUtils.equalsNull(packageName)) {
        return false;
    }
    PackageManager pm = ContextProvider.getApplicationContext()
            .getPackageManager();
    List<PackageInfo> list = pm
            .getInstalledPackages(PackageManager.PERMISSION_GRANTED);
    for (PackageInfo p : list) {
        if (packageName.equals(p.packageName)) {
            return true;
        }
    }
    return false;
}