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. [FE] uni-app 导航栏开发指南

    一种是 原生导航栏添加自定义按钮.简单明了. pages.json 配置 { "path": "pages/log/log", "style" ...

  2. [Contract] 测试 Solidity 合约代码的两种方式 与 优缺点

    第一种,使用 Truffle 这类继承了测试工具的框架,只要编写 js 脚本就可以测试 web3 与合约的逻辑. 优点是完全可控,粒度够细,便于集成测试:缺点是需要花费一些时间编写测试脚本,不过值得. ...

  3. 使用ssh连接远程仓库的方法(github)

    使用ssh连接远程仓库的方法 但是当我登录虚拟机想提交csapp的代码时,我发现需要验证我的账号密码,感觉每次提交都要输入这个很麻烦.然后就在网上查询了下为何提交代码需要输入账号密码. 使用 HTTP ...

  4. C# - 能否让 SortedSet.RemoveWhere 内传入的委托异步执行

    TL;DR; 若想充分利用 RemoveWhere 带来的性能优势,建议传入判断是否删除元素的委托内采取同步操作.若一定要在该委托内使用异步操作,可以采用本文中绕行的方法,但摈弃了 RemoveWhe ...

  5. 习题8 #第8章 Verilog有限状态机设计-1 #Verilog #Quartus #modelsim

    1. 设计一个"111"串行数据检测器.要求是:当检测到连续3个或3个以上的"1"时输出为1,其他输入情况下输出为0. (1)思路分析:参照本章前文的范例,如第 ...

  6. Servlet注解的使用,简化配置 以及,使用模板方法设计模式优化oa项目

    Servlet注解的使用,简化配置 以及,使用模板方法设计模式优化oa项目 每博一文案 有句谚语说:"一怒之下踢石头,只有痛着脚趾头." 比一件糟糕的事情更可拍的,是你用糟糕的态度 ...

  7. centos 7 开启 httpd 服务和 80 端口

    centos 7 开启 httpd 服务和 80 端口 yum install -y httpd systemctl start httpd firewall-cmd --add-service=ht ...

  8. Golang重复Rails Devise gem密码加密

    https://github.com/haimait/go-devise-encryptor package main import ( "fmt" //devisecrypto ...

  9. C数据结构:树和森林存储方式与遍历方式

    文章目录 树的存储方式 双亲表示法 孩子链表表示法 孩子兄弟表示法(二叉树表示法) 树和二叉树的转换 森林和二叉树的转换 树和森林的遍历 树的遍历方式 森林的遍历方式 浅谈一下几个问题 为什么树没有中 ...

  10. sqlserver给某个用户授权某张表得操作权限,并利用这个用户进行跨库查询

    Sql表授权 创建用户 此时,改用户登录是看不到任何表的 设置权限         创建连接   EXEC sp_addlinkedserver 'LinkName','','SQLOLEDB','要 ...