1、效果图

鸿蒙手机 --> 关于手机的截图:

Android程序获取鸿蒙手机设备信息的截图:

2、实现

本案例DEMO的实现主要借鉴了网上现有的资料: https://blog.csdn.net/chenzhengfeng/article/details/119868210

并在此基础上进行了扩展、封装,希望能帮到有需要的小伙伴们~

2.1、鸿蒙工具类封装 HarmonyUtils

import android.text.TextUtils;
import java.lang.reflect.Method; /**
* 齐行超
* 2020-02-16
*/
public class HarmonyUtils {
/**
* 是否为鸿蒙系统
*
* @return true为鸿蒙系统
*/
public static boolean isHarmonyOs() {
try {
Class<?> buildExClass = Class.forName("com.huawei.system.BuildEx");
Object osBrand = buildExClass.getMethod("getOsBrand").invoke(buildExClass);
return "Harmony".equalsIgnoreCase(osBrand.toString());
} catch (Throwable x) {
return false;
}
} /**
* 获取鸿蒙系统版本号
*
* @return 版本号
*/
public static String getHarmonyVersion() {
return getProp("hw_sc.build.platform.version", "");
} /**
* 获取属性
* @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;
} /**
* 获得鸿蒙系统版本号(含小版本号,实际上同Android的android.os.Build.DISPLAY)
* @return 版本号
*/
public static String getHarmonyDisplayVersion() {
return android.os.Build.DISPLAY;
}
}

2.2、HarmonyUtils的调用

当前案例中,在一个activity中实现了对HarmonyUtils工具类的调用。

Activity代码:


import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle;
import android.widget.TextView; public class HarmonyActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_harmony); TextView tv_is_harmony = findViewById(R.id.tv_is_harmony);
TextView tv_harmony_version = findViewById(R.id.tv_harmony_version);
TextView tv_harmony_display_version = findViewById(R.id.tv_harmony_display_version); boolean isHarmony = HarmonyUtils.isHarmonyOs();
tv_is_harmony.setText("is harmony ? \n "+ isHarmony); String harmonyVersion = HarmonyUtils.getHarmonyVersion();
tv_harmony_version.setText("harmony version is: \n "+harmonyVersion); String displayVersion = HarmonyUtils.getHarmonyDisplayVersion();
tv_harmony_display_version.setText("harmony display version is: \n "+displayVersion);
}
}

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
tools:context=".HarmonyActivity"> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="is harmony ?"
android:id="@+id/tv_is_harmony"
android:textSize="20sp"
android:layout_marginTop="20dp"
app:layout_constraintTop_toTopOf="parent"/> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/tv_is_harmony"
android:id="@+id/tv_harmony_version"
android:textSize="20sp"
android:layout_marginTop="20dp"
android:text="harmony version"/> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/tv_harmony_version"
android:id="@+id/tv_harmony_display_version"
android:textSize="20sp"
android:layout_marginTop="20dp"
android:text="harmony display version"/> </androidx.constraintlayout.widget.ConstraintLayout>

Android程序获取鸿蒙手机设备信息(是否鸿蒙手机、版本号、小版本号等)的更多相关文章

  1. 【转】android 安卓APP获取手机设备信息和手机号码的代码示例

    http://blog.csdn.net/changemyself/article/details/7421476 下面我从安卓开发的角度,简单写一下如何获取手机设备信息和手机号码 准备条件:一部安卓 ...

  2. android 安卓APP获取手机设备信息和手机号码的代码示例

    下面我从安卓开发的角度,简单写一下如何获取手机设备信息和手机号码 准备条件:一部安卓手机.手机SIM卡确保插入手机里.eclipse ADT和android-sdk开发环境 第一步:新建一个andro ...

  3. iOS开发-Swift获取手机设备信息(UIDevice)

    使用UiDevice获取设备信息 获取设备名称 let name = UIDevice.currentDevice().name 获取设备系统名称 let systemName = UIDevice. ...

  4. IOS 获取更多的设备信息

    ●  如果想获得更多的设备信息,比如 ●  设备型号.CPU情况.内存使用情况.硬盘使用情况 ●  是否越狱.装了哪些传感器.当前运行的进程 ●  ... ... ●  有2种方法获取更多的设备信息 ...

  5. 小程序开发之获取客户来源 scene 场景值 手机设备信息

    为什么要获取客户来源 用作数据分析,根据客户来源,做精准转化! 判断客户来源入口方式 1.通过官方的scene场景值 常见场景值 场景值ID 说明 1001 发现栏小程序主入口,「最近使用」列表 10 ...

  6. java翻译到mono C#实现系列(3) 获取手机设备信息(残缺,)

    using System; using Android.App; using Android.Content; using Android.Runtime; using Android.Views; ...

  7. ?Object-C获取手机设备信息

    一.获取UiDevice设备信息 // 获取设备名称 NSString *name = [[UIDevice currentDevice] name]; // 获取设备系统名称 NSString *s ...

  8. ?Swift获取手机设备信息

    使用UiDevice获取设备信息: 获取设备名称 let name = UIDevice.currentDevice().name 获取设备系统名称 let systemName = UIDevice ...

  9. iOS开发-Object-C获取手机设备信息(UIDevice)

    一.获取UiDevice设备信息 // 获取设备名称 NSString *name = [[UIDevice currentDevice] name]; // 获取设备系统名称 NSString *s ...

  10. ADB——查看手机设备信息

    查看设备信息 查看手机型号 adb shell getprop ro.product.model 查看电池状况 adb shell dumpsys battery ''' Current Batter ...

随机推荐

  1. vue-cli快速搭建项目的几个文件(二)

    =======ggcss样式======== :root{     --bgColor : #d3252a;     --pinkColor : #ff4e81;     --textColor :  ...

  2. js实现一个拖拽效果(本例vue中),边界限定,获取鼠标坐标,div坐标

    有事没事搞个图: demo: <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...

  3. 【强化学习】Markov Decision processes【二】

    目录 Markov Decision processes Markov Process Markov reward process Markov Decision processes 马尔可夫决策过程 ...

  4. ruby http请求组件

    github地址 https://github.com/rest-client/rest-client gemfile里添加 gem 'rest-client', '~> 2.0' 执行 bun ...

  5. ls的输出格式

    在Linux中,如果在一个目录下面执行ls -al命令,输出格式如下: ls -al总共输出7列,下面对每一列进行说明. 第一列表示这个文件的权限与类型,它总共有10位,每个位的作用如下图所示: 其中 ...

  6. Rust 错误处理

    rust 处理错误,不使用 try catch, 而是使用 Result<T, E>. 简单的处理rust错误 在各种关于rust错误处理的文档中,为了解释清楚其背后的机制,看着内容很多, ...

  7. margin-bottom:-1px无效的问题

    在实现tab的时候,margin-bottom:-1px无效的问题 active的tab项,要指定他的border-top, 如: border-top: 1px solid #fff; border ...

  8. 西门子PLC设备如何接入AIRIOT物联网低代码平台 ?

    西门子PLC设备广泛应用于工业控制领域,高性能和稳定是它最大的优势.下面我们要把西门子300 1200 1500 PLC设备连接到AIRIOT物联网低代码平台,具体操作如下所示: 西门子驱动配置(配套 ...

  9. python 日志 logging模块详解

    1.基本使用 配置logging基本的设置,然后在控制台输出日志, import logging logging.basicConfig(level=logging.INFO, format='%(a ...

  10. 美团一面问我i++跟++i的区别是什么

    美团一面问我i++跟++i的区别是什么 面试官:"i++跟++i的区别是什么?" 我:"i++是先使用然后再执行+1的操作,++i是先执行+1的操作然后再去使用i&quo ...