2
0

More than 3 years have passed since last update.

ファーウェイ端末であるかどうか判断する方法

Last updated at Posted at 2021-06-22

ファーウェイ端末であるかどうか判断するソースコードは次の通りです。

public class HuaweiUtil {

    public static String getManufacturer() {
        try {
            Class<?> classType = Class.forName("android.os.SystemProperties");
            Method getMethod = classType.getDeclaredMethod("get", new Class<?>[]{String.class});
            return (String) getMethod.invoke(classType, new Object[] {"ro.product.manufacturer"});
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static boolean isHuaweiDevice() {
        String manufacturer = getManufacturer();
        if (null == manufacturer) {
            return false;
        }

        return manufacturer.equalsIgnoreCase("HUAWEI");
    }
}
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0