public static boolean hasNotchInScreen(Activity activity) {
if (Build.VERSION.SDK_INT >= 28) {
try {
DisplayCutout displayCutout = activity.getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
if (displayCutout != null) {
return true;
}
} catch (Exception e) {
return false;
}
} else {
String manufacturer = Build.MANUFACTURER;
if (manufacturer == null || manufacturer.length() == 0) {
return false;
} else if (manufacturer.equalsIgnoreCase("HUAWEI")) {
return hasNotchHw(activity);
} else if (manufacturer.equalsIgnoreCase("xiaomi")) {
return hasNotchXiaoMi(activity);
} else if (manufacturer.equalsIgnoreCase("oppo")) {
return hasNotchOPPO(activity);
} else if (manufacturer.equalsIgnoreCase("vivo")) {
return hasNotchVIVO(activity);
} else {
return false;
}
}
return false;
}
public static boolean hasNotchVIVO(Activity activity) {
try {
Class<?> c = Class.forName("android.util.FtFeature");
Method get = c.getMethod("isFeatureSupport", int.class);
return (boolean) (get.invoke(c, 0x20));
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public static boolean hasNotchOPPO(Activity activity) {
try {
return activity.getPackageManager().hasSystemFeature("com.oppo.feature.screen.heteromorphism");
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
public static boolean hasNotchXiaoMi(Activity activity) {
try {
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("getInt", String.class, int.class);
return (int) (get.invoke(c, "ro.miui.notch", 1)) == 1;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public static boolean hasNotchHw(Activity activity) {
try {
ClassLoader cl = activity.getClassLoader();
Class HwNotchSizeUtil = cl.loadClass("com.huawei.android.util.HwNotchSizeUtil");
Method get = HwNotchSizeUtil.getMethod("hasNotchInScreen");
return (boolean) get.invoke(HwNotchSizeUtil);
} catch (Exception e) {
return false;
}
}