HarmonyOS 如何获取app当前的versionCode设备唯一标识码?

app当前版本号调用的deviceInfo.buildVersion,但是返回结果始终是0,怎样获取app当前的versionCode设备唯一标识码?

阅读 502
1 个回答

获取app当前的versionCode参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-bundlemanager-V5\#bundlemanagergetbundleinfoforself

参考示例:

DeviceUtil.getInfoV2().then((bundleInfo: bundleManager.BundleInfo) => {
  let version: number = bundleInfo.versionCode
  console.log('version' + version)
  const apiClient = axios.create({
    baseURL: 'https://api.btime.com/',
    timeout: 1000,
    headers: { 'User-Agent': 'bjtime', 'Referer': 'harmony-app.btime.com' }
  });

  apiClient.interceptors.request.use((config: InternalAxiosRequestConfig) => {
    if (!config.params) {
      config.params = {}
    }
    config.params['channel'] = 'huawei_harmony';
    config.params['os'] = deviceInfo.productModel;
    config.params['os_ver'] = deviceInfo.osFullName;
    config.params['os_type'] = 'Harmony';
    config.params['carrier'] = '';
    config.params['token'] = deviceInfo.serial;
    config.params['sid'] = '';
    config.params['timestamp'] = '';
    config.params['src'] = 'lx_harmony';
    config.params['net'] = '';
    config.params['push_id'] = '';
    config.params['push_switch'] = '';
    config.params['location_citycode'] = '';

    return config;
  }, (error: AxiosError) => {
    return Promise.reject(error);
  });
})