欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 美食 > 鸿蒙获取 APP 信息及手机信息

鸿蒙获取 APP 信息及手机信息

2025/4/19 15:44:17 来源:https://blog.csdn.net/SophieBryant/article/details/144292516  浏览:    关键词:鸿蒙获取 APP 信息及手机信息

前言:获取 APP 版本信息可以通过 bundleManager.getBundleInfoForSelfSync(bundleFlags) 去获取,获取手机信息可以通过  @kit.BasicServicesKit 库去获取,以下是封装好的工具类。

import bundleManager from '@ohos.bundle.bundleManager';
import { deviceInfo } from '@kit.BasicServicesKit';
import { intl } from '@kit.LocalizationKit';/*** 获取手机信息*/
export default class PhoneUtils {private static instance: PhoneUtils = new PhoneUtils();private versionCode: string = ""private versionName: string = ""private constructor() {let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULTconst data:bundleManager.BundleInfo = bundleManager.getBundleInfoForSelfSync(bundleFlags)this.versionCode = data.versionCode.toString()this.versionName = data.versionName.toString()}public static getInstance(): PhoneUtils {return PhoneUtils.instance}/*** 獲取 Code* @returns*/getAppCode(): string {return this.versionCode}/*** 获取 Version* @returns*/getVersionName(): string {return this.versionName}/*** 手機版本*/getPhoneVersion(): string {return deviceInfo.osFullName}/*** 获取系统语言*/getPhoneLanguage(): string {let locale = new intl.Locale();return locale.language}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词