From 7cd5e812882e999443220e9c71103b3e3c476c71 Mon Sep 17 00:00:00 2001 From: nilupeng <qingingrunt2010@qq.com> Date: Fri, 12 Aug 2022 06:58:54 +0000 Subject: [PATCH] 提现,支付密码 --- app/src/main/java/com/runt/open/mvvm/util/DeviceUtil.java | 75 ++++++++++++++++++++++++++++--------- 1 files changed, 57 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/runt/open/mvvm/util/DeviceUtil.java b/app/src/main/java/com/runt/open/mvvm/util/DeviceUtil.java index 58761bb..37f7b36 100644 --- a/app/src/main/java/com/runt/open/mvvm/util/DeviceUtil.java +++ b/app/src/main/java/com/runt/open/mvvm/util/DeviceUtil.java @@ -293,25 +293,7 @@ return 0; } - /** - * dp获取dip - * @param dp - * @return - */ - public static int convertDpToPixel(float dp, Context context) { - DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); - return (int) (dp * displayMetrics.density); - } - /*** - * px获取dip - * @param pixel - * @return - */ - public static int convertPixelToDp(int pixel, Context context) { - DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); - return (int) (pixel / displayMetrics.density); - } public static String getSerialNumber(Context context) { String serial = ""; @@ -371,4 +353,61 @@ } return ""; } + + /** + * check the system is harmony os + * + * @return true if it is harmony os + */ + public static boolean isHarmonyOS() { + try { + Class clz = Class.forName("com.huawei.system.BuildEx"); + Method method = clz.getMethod("getOsBrand"); + return "harmony".equals(method.invoke(clz)); + } catch (ClassNotFoundException e) { + Log.e(TAG, "occured ClassNotFoundException"); + } catch (NoSuchMethodException e) { + Log.e(TAG, "occured NoSuchMethodException"); + } catch (Exception e) { + Log.e(TAG, "occur other problem"); + } + return false; + } + + /** + * 获取鸿蒙系统版本号 + */ + public static String getHarmonyOsVersion() { + if (isHarmonyOS()) { + try { + Class cls = Class.forName("android.os.SystemProperties"); + Method method = cls.getMethod("get", String.class); + return method.invoke(cls, "ro.huawei.build.display.id").toString(); + //android.os.Build.DISPLAY + } catch ( Exception e) { + } + } + return "-1"; + } + + /** + * 获取属性 + * @param property + * @param defaultValue + * @return + */ + private static String getProp(String property, String defaultValue) { + try { + Class spClz = Class.forName("android.os.SystemProperties"); + Method method = spClz.getDeclaredMethod("get", String.class); + String value = (String) method.invoke(spClz, property); + if (TextUtils.isEmpty(value)) { + return defaultValue; + } + return value; + } catch (Throwable e) { + e.printStackTrace(); + } + return defaultValue; + } } -- Gitblit v1.9.1