刘海屏手机越来越多,App需要适配。

/*** 判断是否是刘海屏* @return*/
public static boolean hasNotchScreen(Activity activity){if (getInt("ro.miui.notch",activity) == 1 || hasNotchAtHuawei(activity) || hasNotchAtOPPO()|| hasNotchAtVivo(activity) || isAndroidP(activity) != null){ //TODO 各种品牌return true;}return false;
}/*** Android P 刘海屏判断* @param activity* @return*/
public static DisplayCutout isAndroidP(Activity activity){View decorView = activity.getWindow().getDecorView();if (decorView != null && android.os.Build.VERSION.SDK_INT >= 28){WindowInsets windowInsets = decorView.getRootWindowInsets();if (windowInsets != null)return windowInsets.getDisplayCutout();}return null;
}/*** 小米刘海屏判断.* @return 0 if it is not notch ; return 1 means notch* @throws IllegalArgumentException if the key exceeds 32 characters*/
public static int getInt(String key,Activity activity) {int result = 0;if (isXiaomi()){try {ClassLoader classLoader = activity.getClassLoader();@SuppressWarnings("rawtypes")Class SystemProperties = classLoader.loadClass("android.os.SystemProperties");//参数类型@SuppressWarnings("rawtypes")Class[] paramTypes = new Class[2];paramTypes[0] = String.class;paramTypes[1] = int.class;Method getInt = SystemProperties.getMethod("getInt", paramTypes);//参数Object[] params = new Object[2];params[0] = new String(key);params[1] = new Integer(0);result = (Integer) getInt.invoke(SystemProperties, params);} catch (ClassNotFoundException e) {e.printStackTrace();} catch (NoSuchMethodException e) {e.printStackTrace();} catch (IllegalAccessException e) {e.printStackTrace();} catch (IllegalArgumentException e) {e.printStackTrace();} catch (InvocationTargetException e) {e.printStackTrace();}}return result;
}/*** 华为刘海屏判断* @return*/
public static boolean hasNotchAtHuawei(Context context) {boolean ret = false;try {ClassLoader classLoader = context.getClassLoader();Class HwNotchSizeUtil = classLoader.loadClass("com.huawei.android.util.HwNotchSizeUtil");Method get = HwNotchSizeUtil.getMethod("hasNotchInScreen");ret = (boolean) get.invoke(HwNotchSizeUtil);} catch (ClassNotFoundException e) {AppLog.e("hasNotchAtHuawei ClassNotFoundException");} catch (NoSuchMethodException e) {AppLog.e("hasNotchAtHuawei NoSuchMethodException");} catch (Exception e) {AppLog.e( "hasNotchAtHuawei Exception");} finally {return ret;}
}public static final int VIVO_NOTCH = 0x00000020;//是否有刘海
public static final int VIVO_FILLET = 0x00000008;//是否有圆角/*** VIVO刘海屏判断* @return*/
public static boolean hasNotchAtVivo(Context context) {boolean ret = false;try {ClassLoader classLoader = context.getClassLoader();Class FtFeature = classLoader.loadClass("android.util.FtFeature");Method method = FtFeature.getMethod("isFeatureSupport", int.class);ret = (boolean) method.invoke(FtFeature, VIVO_NOTCH);} catch (ClassNotFoundException e) {AppLog.e( "hasNotchAtVivo ClassNotFoundException");} catch (NoSuchMethodException e) {AppLog.e(  "hasNotchAtVivo NoSuchMethodException");} catch (Exception e) {AppLog.e(  "hasNotchAtVivo Exception");} finally {return ret;}
}
/*** OPPO刘海屏判断* @return*/
public static boolean hasNotchAtOPPO(Context context) {return  context.getPackageManager().hasSystemFeature("com.oppo.feature.screen.heteromorphism");
}
// 是否是小米手机
public static boolean isXiaomi() {return "Xiaomi".equals(Build.MANUFACTURER);
}

暂时未发现其他刘海屏手机适配方案。。。

Android 判断是否是刘海屏相关推荐

  1. Android 判断手机是否刘海屏适配各主流手机型号

    import android.annotation.SuppressLint; import android.app.Activity; import android.os.Build; import ...

  2. Android 判断是否有刘海屏

    文档 查阅了网上很多文章几乎都是抄的下面这些文档中的内容,所以就不详细说了,大家可以直接去看就可以了. android P 在 android P 上 google 官方提供了标准的 api 来识别是 ...

  3. html5安卓机判断刘海屏,Android判断是否为刘海屏

    主要总结主流品牌小米.华为.oppo.vivo的刘海屏判断.在某些特殊页面需要适配刘海屏时,可以用以下方法判断. 或者判断屏幕比例是否大于2. /** * 小米刘海屏判断. */ public sta ...

  4. android小米刘海屏幕适配,Android、iPhone手机刘海屏适配判断

    一.简介 手机屏幕的正上方居中位置(下图黑色区域)会被挖掉一个孔,屏幕被挖掉的区域无法正常显示内容,这种类型的屏幕就是刘海屏,也有其他叫法:挖孔屏.凹凸屏等等 二.Android刘海屏适配判断 1.判 ...

  5. android兼容小米xiaomi刘海屏解决方案

    引用自小米官方文档,这里缩减了一些内容,捡取重要内容. 转载请标明出处: https://blog.csdn.net/DJY1992/article/details/80688376 本文出自:[奥特 ...

  6. Android适配全面屏/刘海屏

    目前国内厂商已经推出的刘海屏Android手机有华为P20 pro, vivo X21,OPPO R15. 1.华为刘海屏的官方适配文档 https://devcenter-test.huawei.c ...

  7. Android 屏幕适配 - 支持刘海屏

    刘海屏是指某些设备显示屏上的一个区域延伸到显示面,这样既能为用户提供全面屏体验,又能为设备正面的重要传感器留出空间.Android 在搭载 Android 9(API 级别 28)及更高版本的设备上正 ...

  8. Android 屏幕适配之刘海屏适配(notch 适配)

    引言 首先先翻译一下 notch 即 凹痕 的意思,那我们就认为是 "刘海" 就可以了. 目前,市场手机的潮流就是推出 全面屏.齐刘海 的手机,比如现在的华为.oppo .vivo ...

  9. android兼容huawei手机刘海屏解决方案

    引用自华为官方文档:doc/50114 ,这里缩减了一些内容,捡取重要内容. 转载请标明出处: https://blog.csdn.net/djy1992/article/details/806835 ...

最新文章

  1. TFS 2008 中文版安装记录
  2. 为什么不建议企业组织自行配置SD-WAN?—Vecloud微云
  3. mysql 逐列读取_mysql – 根据其他列如何使用逐列
  4. sqoop数据倾斜_北京卓越讯通大数据岗位面试题分享
  5. 做一个java项目要经过那些正规的步骤
  6. python语法基础整理_Python基础
  7. 立即执行函数(IIFE)闭包
  8. linux系统 安装mysql,在linux系统中安装MySQL
  9. 15muduo_base库源码分析(六)
  10. NGINX访问日志和错误日志
  11. Python全栈开发记录_第六篇(生成器和迭代器)
  12. 你电脑上「最引以为豪」的软件是什么?
  13. [转贴]色彩调和的原理
  14. 易捷行云EasyStack 云平台携手飞腾S2500推动国产化云生态建设
  15. Android接收和发送短信
  16. outlook 签名 设置
  17. 自媒体:公众号内容可以同步到头条吗
  18. 派森编程python_派森学python
  19. 分享 13 个可以在线制作 360 度全景视图的网站
  20. C语言速成笔记 —— 考点详解 知识点图解

热门文章

  1. oracle20c最新版本,Oracle DUL支持Oracle 20c
  2. DUL[2020-CVPR]
  3. 凡事预则立,不预则废——自考有感
  4. 数据可视化之设计经验分享:轻松三步教你学会制作数据可视化大屏思路
  5. html+css+小图标,HTML+CSS入门 一个简单实用的CSS loading图标
  6. 图片怎么转换成PDF格式?这两种方法赶紧记下
  7. formality软件使用教程
  8. 回文日期 php,c语言程序实例大全,220个详细程序源代码
  9. 调用百度网盘开放平台接口,操作百度网盘中的文件,上传、下载等
  10. 利用sympy库求解常微分方程:dsolve()函数