#鸿蒙获取设备唯一标识
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();
}
/**