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. 从零开始写 Docker(十二)---实现 mydocker stop 停止容器

    本文为从零开始写 Docker 系列第十二篇,实现类似 docker stop 的功能,使得我们能够停止指定容器. 完整代码见:https://github.com/lixd/mydocker 欢迎 ...

  2. Java中HTTP下载文件——并解决跨域

    1.常用的需要设置的MIME类型 任何文件(二进制文件) application/octet-stream .doc application/msword .dot application/mswor ...

  3. .Net 8.0 下的新RPC,IceRPC之"请求"生命线意义非凡

    作者引言 很高兴啊,我们来到了IceRPC之"请求"生命线意义非凡,号称"死亡时间"的追命线,颤抖吧! "请求"生命线之意义非凡 本文将深入 ...

  4. 三:瑞芯微OK3399-C开发板

    场景一 给广告机加上一双智慧的眼睛,时刻关注这经过自己面前的每一个人,把他(她)们的性别.年龄.胖瘦.着装风格.经过频次.观看广告的时间.每个广告观看的人数等等一一记录下来,为广告机运营商.广告创业设 ...

  5. Spring 是如何造出一个 Bean 的

    前言 使用 Java 作为第一开发语言的朋友们,相信大家或多或少的都使用过 Spring 这个开发框架,可以说 Spring 框架真是我们 Java 程序员的春天,在 Spring 中 Bean 是其 ...

  6. HouseParty原创故事全角色关系及主线剧情介绍(最新版)

    这是原创故事的主要的角色的主线及支线剧情的介绍及攻略和注意事项等. 这里的图比哔哩哔哩上的图清楚一点,哔哩哔哩同号:宅猫君007 以上是全角色的关系图 最新版本的游戏下载就在我的网站上:https:/ ...

  7. deepin下的系统,如何为root用户添加密码

  8. 一键自动化博客发布工具,用过的人都说好(infoq篇)

    infoq的博客发布界面也是非常简洁的.首页就只有基本的标题,内容和封面图片,所以infoq的实现也相对比较简单. 一起来看看吧. 前提条件 前提条件当然是先下载 blog-auto-publishi ...

  9. 阿里云sdk调用

    slb调用 环境包安装 pip install alibabacloud_credentials  --trusted-host mirrors.aliyun.com  -i  http://mirr ...

  10. 推荐2款开源、美观的WinForm UI控件库

    前言 今天大姚给大家分享2款开源.美观的WinForm UI控件库,希望可以帮助到有需要的同学. WinForm介绍 WinForm是一个传统的桌面应用程序框架,它基于 Windows 操作系统的原生 ...