赞
踩
#鸿蒙获取设备唯一标识
package com.viaton.common.utils;
import ohos.app.Context;
import ohos.bundle.BundleInfo;
import ohos.data.distributed.common.KvManagerConfig;
import ohos.data.distributed.common.KvManagerFactory;
import ohos.system.DeviceInfo;
public class DeviceUtils {
public static Context appContext; /** * 获取APP版本名称 * * @return */ public static String getVersionName() { BundleInfo bundleInfo = getBundleInfo(); if (bundleInfo != null) { return bundleInfo.getVersionName(); } return ""; } /** * 获取APP版本号 * * @return */ public static int getVersionCode() { BundleInfo bundleInfo = getBundleInfo(); if (bundleInfo != null) { return bundleInfo.getVersionCode(); } return 0; } /** * 获取设备唯一标识 * * @return */ public static String getDeviceId() { return KvManagerFactory.getInstance().createKvManager(new KvManagerConfig(appContext)).getLocalDeviceInfo().getId(); } /** * 获取设备型号 * * @return */ public static String getDeviceName() { return KvManagerFactory.getInstance().createKvManager(new KvManagerConfig(appContext)).getLocalDeviceInfo().getName() + " " + DeviceInfo.getName(); } private static BundleInfo getBundleInfo() { try { return appContext.getBundleManager().getBundleInfo(appContext.getBundleName(), 0x00000000); } catch (Exception e) { e.printStackTrace(); return null; } }
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。