2018-05-14

目前支持判断华为、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;
    }


}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • #海底两万里#【伙伴共读第52天】 今天读叶嘉莹的《唐宋词十七讲》第十五到十七讲 《王沂孙(上、中、下)》...
    维C多阅读 1,594评论 0 0
  • 那不是一个向阳的地方 却弥漫着阳光的清香 永恒的绿 老叶硬朗 新芽张扬 掩饰了不可违的黄 枯叶富态 毛尖水汪 装满...
    秦巴佬阅读 132评论 0 0
  • 人是一种可塑性极强的生物,对人的塑造力量最强的就是行动,长期从事特定的行动必然会塑造特定的人物,所以良好的行为习惯...
    五点砍柴阅读 485评论 0 2
  • 好多公司有静默安装的需求(就是不用人去确认就把程序更新了)目前主流的技术有无障碍模式、辅助程序加pm命令模式、系统...
    大笨龙___阅读 542评论 1 8