androidhuawei-mobile-serviceshuawei-developers

Android : How to detect the device is Huawei or not?


I am trying to find a way to detect whether the device is Huawei or not. My app has a piece of code that causes a crash on Huawei devices, I want to avoid executing that code if the device is Huawei.

I don't want to use checks based on GMS & HMS availability cause my app does not contain dependency for these packages.

Thanks


Solution

  • Try this. The Code standard is poor, but it gets the job done. I don't think Huawei will ever change its name.

    private boolean isHuaweiDevice(){
        String manufacturer = android.os.Build.MANUFACTURER;
        String brand =  android.os.Build.BRAND;
        return  manufacturer.toLowerCase().contains("huawei") ||  brand.toLowerCase().contains("huawei");
    }