目前支持判斷華為焦除、oppo、vivo的劉海屏手機
public class DisplayCutoutUtils {
private Context mContext;
public DisplayCutoutUtils(Context mContext) {
this.mContext = mContext;
}
/**
* @return 返回是否有劉海屏
*/
public boolean hasNotchInScreen() {
if (PhoneDetector.isEmui()) {
boolean ret = false;
try {
ClassLoader cl = mContext.getClassLoader();
Class HwNotchSizeUtil = cl.loadClass("com.huawei.android.util.HwNotchSizeUtil");
Method get = HwNotchSizeUtil.getMethod("hasNotchInScreen");
ret = (boolean) get.invoke(HwNotchSizeUtil);
} catch (ClassNotFoundException e) {
Log.e("test", "hasNotchInScreen ClassNotFoundException");
} catch (NoSuchMethodException e) {
Log.e("test", "hasNotchInScreen NoSuchMethodException");
} catch (Exception e) {
Log.e("test", "hasNotchInScreen Exception");
} finally {
return ret;
}
} else if (PhoneDetector.isOppo()) {
return mContext.getPackageManager()
.hasSystemFeature("com.oppo.feature.screen.heteromorphism");
} else if (PhoneDetector.isVivo()) {
boolean ret = false;
try {
ClassLoader cl = mContext.getClassLoader();
Class FtFeature = cl.loadClass("com.util.FtFeature");
Method get = FtFeature.getMethod("isFeatureSupport", int.class);
ret = (boolean) get.invoke(FtFeature, 0x00000020);
} catch (ClassNotFoundException e) {
Log.e("test", "hasNotchInScreen ClassNotFoundException");
} catch (NoSuchMethodException e) {
Log.e("test", "hasNotchInScreen NoSuchMethodException");
} catch (Exception e) {
Log.e("test", "hasNotchInScreen Exception");
} finally {
return ret;
}
}
return false;
}
}