Android 通过包名来判断是否安装APP

已知包名来判断APP是否安装,代码如下:

    public boolean isInstalled() {
        String packageName3 = "com.xx.xxx";
        if (packageName3 != null && !"".equals(packageName3)) {
            try {
                getPackageManager().getApplicationInfo(packageName3, 0);
                return true;
            } catch (PackageManager.NameNotFoundException var3) {
                try {
                    getPackageManager().getApplicationInfo(packageName3, 0);
                    return true;
                } catch (PackageManager.NameNotFoundException var2) {
                    return false;
                }
            }
        } else {
            return false;
        }
    }


你可能感兴趣的:(Android基础,android)