【HarmonyOS NEXT】如果获取应用相关信息,比如应用版本号、uuid、ip地址

 【关键字】

版本号 / UUID / IP / OAID / AAID / 唯一标识

【问题描述】

麻烦咨询一下,如何获取一些应用开发必要信息:

  • App信息:如应用版本号、编译版本号

  • 唯一标志符信息:如uuid、udid、idfv

  • 网络信息:如局域网ip地址、ipv4与ipv6地址

【解决方案】

import { bundleManager } from '@kit.AbilityKit'

@Entry
@Component
export struct ToLoginPage {
build() {
Column() {
Text('hello')
}
}
onPageShow() {

}
aboutToAppear(): void {
bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION).then((info)=>{
console.info("info:"+info.name)
})
}
}
async function getLocalIp() {
try {
hilog.info(0x00000, TAG, '判断是否存在激活的网络连接');
let hasNet = connection.hasDefaultNetSync()
if (hasNet) {
hilog.info(0x00000, TAG, '存在默认激活的网络');
} else {
hilog.error(0x00000, TAG, '不存在激活的网络');
return
}

let handleResult = await connection.getDefaultNet()
if (handleResult) {
let connectionProperties = await connection.getConnectionProperties(handleResult)
if (connectionProperties && connectionProperties.linkAddresses) {
connectionProperties.linkAddresses.forEach((address: connection.LinkAddress, index: number) => {
hilog.info(0x00000, TAG, '索引:' + index + ',值:' + JSON.stringify(address));
})
}
}
} catch (e) {
hilog.error(0x00000, TAG, `获取网络信息出现异常,异常信息 %{public}s`, JSON.stringify(e) ?? '');
}
}

  • 9
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值