文档管理中心
API参考快应用API系统能力设备信息

设备信息

接口声明

在manifest.json文件的 features属性中增加如下配置。

收起
自动换行
深色代码主题
复制
  1. {"name": "system.device"}

导入模块

在调用接口页面的<script>部分增加如下配置。

收起
自动换行
深色代码主题
复制
  1. import device from '@system.device'

或

收起
自动换行
深色代码主题
复制
  1. var device = require("@system.device")

使用限制

展开

限制条件

说明

适用终端

手机、平板、车机,智慧屏支持部分接口

适用区域

全球

属性(1030+)

展开

属性

类型

默认值

是否必选

说明

platform

object

-

否

用于获取平台信息,该对象包括一个属性值:versionCode,表示平台版本号。

allowTrackOAID(1060+)

boolean

-

否

限制oaid以及HarmonyOS 2.0及以上或Android 10.0及以上的deviceId是否可以用于广告跟踪。设置为true,表示限制用于广告跟踪。该值的更新需要引擎进程重启后生效,否则读取的为引擎缓存的值。

接口定义

展开

接口

描述

device.getInfo(OBJECT)

获取设备信息。

device.getInfoSync(OBJECT)

获取设备信息。

device.getId(OBJECT)

获取设备Id。

device.getDeviceId(OBJECT)

获取设备唯一标识,需要用户授权。

device.getUserId(OBJECT)

获取用户唯一标识。

device.getOAID(OBJECT)

获取匿名设备标识符,建议只在广告的场景使用。

device.getTotalStorage(OBJECT)

获取内部存储空间的总大小,不计算外置sdcard的存储空间。

device.getAvailableStorage(OBJECT)

获取内部存储空间的可用大小,不计算外置sdcard的可用大小。

device.getCpuInfo(OBJECT)

返回CPU信息。

device.onFontScaleChange(OBJECT)

监听系统字体设置比例的改变,当系统字体设置改变时,触发callback回调。在卡片的环境下由宿主应用监听到变化后,通过onConfigurationChanged(Configuration newConfig)通知到fastview sdk,fastview sdk负责事件onFontScaleChange的回调。

device.getServiceCountryCode(OBJECT)

返回当前快应用中心的服务地信息,目前服务地为海外时有些能力不可用,比如微信分享,支付,支付宝支付,微博分享等能力,此接口返回的值不一定与操作系统设置的国家码相同。

device.getCountryCode(OBJECT)

获取当前快应用中心华为账号的注册国家地信息。

device.toLocaleDateTimeString(timeStamp)

将时间戳转换为和系统日期、时间格式相同的字符串。

device.toLocaleDateString(timeStamp)

将时间戳转换为和系统日期格式相同的字符串。

device.toLocaleTimeString(timeStamp)

将时间戳转换为和系统日期格式相同的字符串。

device.host(OBJECT)

获取宿主应用的包名、版本号和版本名。

device.getCarNo(OBJECT)

获取车牌号,需要用户授权。

device.getCarInfoVin(OBJECT)

获取车架号,需要用户授权。

device.getCarEngineNo(OBJECT)

获取发动机号,需要用户授权。

device.getCarNoColor(OBJECT)

获取车牌颜色。

device.getCarRegisterTime(OBJECT)

获取车辆注册日期。

device.getCarSeatsCount(OBJECT)

获取车辆座位数。

device.getCarInfoModel(OBJECT)

获取车辆型号。

device.getCarInfoModelYear(OBJECT)

获取车型年份。

device.getCarManufacturer(OBJECT)

获取车辆制造商。

device.isFoldable()

检测设备是否为可折叠设备。

device.isCodecSupported(codecName)

检查设备是否支持指定参数的编解码器。

device.getInfo(OBJECT)

描述

获取设备信息。

OBJECT参数

展开

参数

类型

是否必填

说明

success

function

否

成功回调。

fail

function

否

失败回调。

complete

function

否

执行结束后的回调。

success返回值:

展开

参数名

类型

说明

brand

string

设备品牌。

manufacturer

string

设备生产商。

model

string

设备型号。

product

string

设备代号。

osType

string

操作系统名称。

osVersionName

string

操作系统版本名称。

osVersionCode

number

操作系统版本号。

platformVersionName

string

运行平台版本名称。

platformVersionCode

number

运行平台版本号。

language

string

系统语言。

region

string

系统地区。

screenWidth

number

屏幕宽。

screenHeight

number

屏幕高。

engineProvider

string

华为扩展参数,非厂商联盟标准,引擎的提供商,返回固定值“huawei”。

windowWidth(1020+)

number

可使用窗口宽度,以屏幕的实际分辨率为单位。

windowHeight(1020+)

number

可使用窗口高度,以屏幕的实际分辨率为单位。

可使用窗口高度=屏幕的高度- 状态栏高度-标题栏高度-虚拟导航栏高度。

cutout(1080+)

array

针对异形屏(比如刘海屏、水滴屏和开孔屏),返回异形区域的位置。包含以下参数:

  • left:cutout左边界和屏幕左边框的距离
  • top:cutout上边界和屏幕上边框的距离
  • right:cutout右边界和屏幕右边框的距离
  • bottom:cutout下边界和屏幕下边框的距离

例如:cutout: [{"left":0,"top":0,"right":955,"bottom":2208}]。

statusBarHeight(1020+)

number

状态栏的高度,以屏幕的实际分辨率为单位。

pixelRatio(1020+)

number

设备像素比(华为扩展接口,非厂商联盟规范)。

screenDensity(1035+)

number

设备的屏幕密度。

screenLogicWidth

number

设备的屏幕逻辑宽度。

screenLogicHeight

number

设备的屏幕逻辑高度。

timeZone(1040+)

string

当前的系统时区。

emuiVer(1040+)

string

EMUI的系统版本号,如9.0.0。

fontScale(1040+)

number

用户字体大小设置。以“系统-设置-通用-字体大小”中的设置为准,例如0.9, 1,1.1,1.2,1.5等。

characteristics(1040+)

string

终端类型,通过读取ro.build.characteristics获取:

default、tv、tablet、phone。缺省为phone。

windowLogicWidth(1040+)

number

  • 在卡片场景下,以750为基准,卡片宿主应用为卡片显示分配的宽度。例如非全屏显示的卡片,该值为小于750的某个值, 比如460。
  • 在快应用场景下,该值与快应用manifest文件中config的designWidth配置,默认为750。

windowLogicHeight(1040+)

number

在卡片场景下特有,以750为基准,卡片宿主应用为卡片显示分配的高度。如果宿主应用没有给卡片分配特定的高度,获取此值将失败。

emuiApiLevel(1050+)

string

系统的api版本号,如18。

marketingName(1060+)

string

机型传播名,如P20Pro。

harmonyOSVer(1078+)

string

HarmonyOS设备版本号,如2.0.0。

vendorOsName(1080+)

string

手机厂商定制的系统名称。

vendorOsVersion(1080+)

string

手机厂商定制的系统版本号。

deviceType(1090+)

string

设备类型。

取值如下:

  • phone:手机
  • tablet:平板
  • tv:智慧屏
  • foldable(1110+):可折叠设备

screenRefreshRate(1100+)

float

屏幕当前显示的刷新率。

获得的帧率可能不是60、90、144等标准帧率值。

示例代码

收起
自动换行
深色代码主题
复制
  1. device.getInfo({
  2. success: function (ret) {
  3. console.log("handling success:",JSON.stringify(ret));
  4. },
  5. fail: function (erromsg, errocode) {
  6. console.log("message:",erromsg,errocode);
  7. }
  8. })

输出结果如下:

收起
自动换行
深色代码主题
复制
  1. device getInfo:{ "brand": "HUAWEI", "manufacturer": "HUAWEI", "model": "ATH-TL00H", "product": "ATH-TL00H", "osType": "android", "osVersionName": "9", "osVersionCode": 28, "platformVersionName": "1.082", "platformVersionCode": 1080, "language": "zh", "region": "CN", "screenWidth": 1080, "screenHeight": 2139, "timeZone": "GMT+08:00", "emuiApiLevel": "19", "emuiVer": "9.1.0", "vendorOsName": "emui","vendorOsVersion": "9.1.0","fontScale": 1, "characteristics": "default", "windowWidth": 1080, "windowHeight": 1995, "cutout": [{"left":0,"top":0,"right":955,"bottom":2208}],"statusBarHeight": 75, "pixelRatio": 3, "engineProvider": "huawei", "screenDensity": 3, "screenLogicWidth": 750, "screenLogicHeight": 1485, "windowLogicWidth": 750, "windowLogicHeight": 1385, "marketingName": "HUAWEI P30", "harmonyOSVer": "" }

device.getInfoSync(OBJECT)(1040+)

描述

获取设备信息。

返回值

展开

参数名

类型

说明

brand

string

设备品牌。

manufacturer

string

设备生产商。

model

string

设备型号。

product

string

设备代号。

osType

string

操作系统名称。

osVersionName

string

操作系统版本名称。

osVersionCode

number

操作系统版本号。

platformVersionName

string

运行平台版本名称。

platformVersionCode

number

运行平台版本号。

language

string

系统语言。

region

string

系统地区。

screenWidth

number

屏幕宽。

screenHeight

number

屏幕高。

engineProvider

string

华为扩展参数,非厂商联盟标准,引擎的提供商,返回固定值“huawei”。

windowWidth(1020+)

number

可使用窗口宽度,以屏幕的实际分辨率为单位。

windowHeight(1020+)

number

可使用窗口高度,以屏幕的实际分辨率为单位。

可使用窗口高度=屏幕的高度- 状态栏高度-标题栏高度-虚拟导航栏高度。

statusBarHeight(1020+)

number

状态栏的高度,以屏幕的实际分辨率为单位。

pixelRatio(1020+)

number

设备像素比(华为扩展接口,非厂商联盟规范)。

screenDensity(1035+)

number

设备的屏幕密度。

timeZone(1040+)

string

当前的系统时区。

emuiVer(1040+)

string

EMUI的系统版本号,如9.0.0。

fontScale(1040+)

number

用户字体大小设置。以“系统-设置-通用-字体大小”中的设置为准,例如0.9, 1,1.1,1.2,1.5等。

characteristics(1040+)

string

终端类型,通过读取ro.build.characteristics获取:

default、tv、tablet、phone。缺省为phone。

windowLogicWidth(1040+)

number

  • 在卡片场景下,以750为基准,卡片宿主应用为卡片显示分配的宽度。例如非全屏显示的卡片,该值为小于750的某个值, 比如460。
  • 在快应用场景下,该值与快应用manifest文件中config的designWidth配置,默认为750。

windowLogicHeight(1040+)

number

在卡片场景下特有,以750为基准,卡片宿主应用为卡片显示分配的高度。如果宿主应用没有给卡片分配特定的高度,获取此值将失败。

emuiApiLevel(1050+)

string

系统的api版本号,如18。

marketingName(1060+)

string

机型传播名,如P20Pro。

harmonyOSVer(1078+)

string

HarmonyOS设备版本号,如2.0.0。

示例代码

收起
自动换行
深色代码主题
复制
  1. try {
  2. const res = device.getInfoSync();
  3. console.log(res.brand);
  4. console.log(res.model);
  5. } catch (e) {
  6. // Do something when catch error
  7. console.log(e.code + e.message);
  8. }

device.getId(OBJECT)

描述

获取设备标识、用户标识、MAC地址。

智慧屏和卡片不支持。

注意

Android 10.0以前需要弹框授权,HarmonyOS 2.0及以上或Android10.0及以上版本不弹框。

OBJECT参数

展开

参数

类型

是否必填

说明

type

array

是

支持device、mac、user三种类型,可以同时提供多个,至少提供一个。

success

function

否

成功回调,参数为:{"device":"1234567890","mac":"abcdef123456","user":"abcdef123456"}每项结果仅在type中有对应类型的时候才会返回,快应用引擎版本从3.2.1.310版本开始,mac返回固定值02:00:00:00:00:00,3.2.1.310版本以前mac在系统版本号为6.0及以上返回固定值:02:00:00:00:00:00。

fail

function

否

失败回调。

complete

function

否

执行结束后的回调。

success返回值:

展开

参数名

类型

说明

device

string

设备唯一标识。Android 10.0以前返回 IMEI 或 MEID,HarmonyOS 2.0及以上或Android 10.0及以上版本返回AAID(应用匿名设备标识符),AAID和快应用相关,每个快应用AAID不同。当清空应用数据或者卸载应用,AAID会发生变化。

mac

string

设备的mac地址。Android 6.0以前返回设备的MAC地址,HarmonyOS 2.0及以上或Android 6.0及以上版本返回固定值。

user

string

用户唯一标识。Android 10.0以前返回 ANDROID_ID,HarmonyOS 2.0及以上或Android 10.0及以上版本返回值和快应用签名值相关,相同的签名值相同。如下情况将导致获取值发生改变:

  1. 恢复出厂设置
  2. 快应用签名指纹改变(HarmonyOS 2.0及以上或Android 10.0及以上版本)

fail返回错误码:

展开

错误码

说明

201

用户拒绝,获取电话状态权限失败。

示例代码

收起
自动换行
深色代码主题
复制
  1. device.getId({
  2. type: ["device", "mac"],
  3. success:function(data) {
  4. console.log("handling success: " + data.device);
  5. },
  6. fail: function(data, code) {
  7. console.log("handling fail, code=" + code);
  8. }
  9. })

device.getDeviceId(OBJECT)

描述

获取设备标识。

智慧屏和卡片不支持。

注意

Android 10.0以前需要弹框授权,HarmonyOS 2.0及以上或Android10.0及以上版本不弹框。

OBJECT参数

展开

参数

类型

是否必填

说明

success

function

否

成功回调。

fail

function

否

失败回调。

complete

function

否

执行结束后的回调。

success返回值:

展开

参数名

类型

说明

deviceId

string

设备唯一标识。Android 10.0以前返回 IMEI 或 MEID,HarmonyOS 2.0及以上或Android 10.0及以上版本返回AAID(应用匿名设备标识符),AAID和快应用相关,每个快应用AAID不同。当清空应用数据或者卸载应用,AAID会发生变化。

fail返回错误码:

展开

错误码

说明

201

用户拒绝授权。

示例代码

收起
自动换行
深色代码主题
复制
  1. device.getDeviceId({
  2. success: function(data) {
  3. console.log("handling success: " + data.deviceId);
  4. },
  5. fail: function(data, code) {
  6. console.log("handling fail, code=" + code);
  7. }
  8. })

device.getUserId(OBJECT)

描述

获取用户标识。

智慧屏和卡片不支持。

注意

无弹框授权。

OBJECT参数

展开

参数

类型

是否必填

说明

success

function

否

成功回调。

fail

function

否

失败回调。

complete

function

否

执行结束后的回调。

success返回值:

展开

参数名

类型

说明

userId

string

用户唯一标识。Android 10.0以前返回 ANDROID_ID,HarmonyOS 2.0及以上或Android 10.0及以上版本返回值和快应用签名值相关,相同的签名值相同。HarmonyOS 2.0及以上或Android 10.0及以上版本该值长度为64个字符。如下情况将导致获取值发生改变:

  1. 恢复出厂设置
  2. 快应用签名指纹改变(HarmonyOS 2.0及以上或Android 10.0及以上版本)

示例代码

收起
自动换行
深色代码主题
复制
  1. device.getUserId({
  2. success: function(data) {
  3. console.log("handling success: " + data.userId);
  4. },
  5. fail: function(data, code) {
  6. console.log("handling fail, code=" + code);
  7. }
  8. })

device.getOAID(OBJECT)(1060+)

描述

获取匿名设备标识符,建议只在广告的场景使用。

智慧屏、车机和卡片不支持。

OBJECT参数

展开

参数

类型

是否必填

说明

success

function

否

成功回调。

fail

function

否

失败回调。

complete

function

否

执行结束后的回调。

success返回值:

展开

参数名

类型

说明

oaid

string

匿名设备标识符。如果当前设备不支持oaid,返回空值。当用户重置广告标识符后,该值发生改变。当手机系统设置项“限制广告跟踪”为开启状态时,返回由0组成的字符串。

示例代码

收起
自动换行
深色代码主题
复制
  1. device.getOAID({
  2. success: function (ret) {
  3. that.OAID = JSON.stringify(ret);
  4. },
  5. fail: function (erromsg, errocode) {
  6. that.OAID = errocode + ': ' + erromsg
  7. },
  8. complete: function () {
  9. prompt.showToast({
  10. message: "请求完成" + device.allowTrackOAID
  11. })
  12. }
  13. })

device.getTotalStorage(OBJECT)

描述

获取内部存储空间的总大小,不计算外置sdcard的存储空间。

OBJECT参数

展开

参数

类型

是否必填

说明

success

function

否

成功回调。

fail

function

否

失败回调。

complete

function

否

执行结束后的回调。

success返回值:

展开

参数名

类型

说明

totalStorage

long

存储空间的总大小,单位是Byte。在Android上返回的是外部存储的总大小。

示例代码

收起
自动换行
深色代码主题
复制
  1. device.getTotalStorage({
  2. success:function(data) {
  3. console.log("handling success: " + data.totalStorage);
  4. },
  5. fail: function(data, code) {
  6. console.log("handling fail, code=" + code);
  7. }
  8. })

device.getAvailableStorage(OBJECT)

描述

获取内部存储空间的可用大小,不计算外置sdcard的可用大小。

OBJECT参数

展开

参数

类型

是否必填

说明

success

function

否

成功回调。

fail

function

否

失败回调。

complete

function

否

执行结束后的回调。

success返回值:

展开

参数名

类型

说明

availableStorage

long

存储空间的可用大小,单位是Byte。在Android上返回的是外部存储的可用大小。

示例代码

收起
自动换行
深色代码主题
复制
  1. device.getAvailableStorage({
  2. success:function(data) {
  3. console.log("handling success: " + data.availableStorage);
  4. },
  5. fail: function(data, code) {
  6. console.log("handling fail, code=" + code);
  7. }
  8. })

device.getCpuInfo(OBJECT)

描述

返回CPU信息。

OBJECT参数

展开

参数

类型

是否必填

说明

success

function

否

成功回调。

fail

function

否

失败回调。

complete

function

否

执行结束后的回调。

success返回值:

展开

参数名

类型

说明

cpuInfo

string

CPU信息。在Android上返回的是/proc/cpuinfo文件的内容。

示例代码

收起
自动换行
深色代码主题
复制
  1. device.getCpuInfo({
  2. success:function(data) {
  3. console.log("handling success: " + data.cpuInfo);
  4. },
  5. fail: function(data, code) {
  6. console.log("handling fail, code=" + code);
  7. }
  8. })

device.onFontScaleChange(OBJECT)(1040+,非厂商联盟规范)

描述

监听系统字体设置比例的改变,当系统字体设置改变时,触发callback回调。在卡片的环境下由宿主应用监听到变化后,通过onConfigurationChanged(Configuration newConfig)通知到fastview sdk,fastview sdk负责事件onFontScaleChange的回调。

OBJECT参数

展开

参数

类型

是否必填

说明

callback

function

否

每次系统字体设置的比例发生变化,会被回调。

callback返回值:

展开

参数名

类型

说明

fontScale

number

用户字体大小设置。以“系统-设置-通用-字体大小”中的设置为准,例如0.9, 1,1.1,1.2,1.5等。

示例代码

收起
自动换行
深色代码主题
复制
  1. device.onFontScaleChange({
  2. callback: function(ret) {
  3. console.log("fontScale ==" + ret.fontScale);
  4. }
  5. })

device.getServiceCountryCode(OBJECT)(1060+)

描述

返回当前快应用中心的服务地信息,目前服务地为海外时有些能力不可用,比如微信分享,支付,支付宝支付,微博分享等能力,此接口返回的值不一定与操作系统设置的国家码相同。

OBJECT参数

展开

参数

类型

是否必填

说明

success

function

否

成功回调。

fail

function

否

失败回调。

complete

function

否

执行结束后的回调。

success返回值:

展开

参数

类型

说明

serviceCountryCode

string

返回当前快应用中心的服务地信息,符合 ISO 3166 标准,如CN,JP。

fail返回错误码:

展开

错误码

说明

200

通用错误。

示例代码

收起
自动换行
深色代码主题
复制
  1. device.getServiceCountryCode({
  2. success: function (ret){
  3. console.log(`serviceCountryCode = ${ret.serviceCountryCode}`)
  4. },
  5. fail: function(erromsg, errocode){
  6. console.log(`error message = ${erromsg}, error code = ${errocode}`)
  7. },
  8. complete: function () {
  9. prompt.showToast({
  10. message: "请求完成"
  11. })
  12. }
  13. })

device.getCountryCode(OBJECT)(1070+,非厂商联盟规范)

描述

获取当前快应用中心华为账号的注册国家地信息。

说明

使用华为加载器调试时,无法获取对应信息。

OBJECT参数

展开

参数

类型

是否必填

说明

success

function

否

成功回调。

fail

function

否

失败回调。

complete

function

否

执行结束后的回调。

success返回值:

展开

参数

类型

说明

countryCode

string

返回当前快应用中心的服务地信息,符合 ISO 3166 标准,如CN,JP。

fail返回错误码:

展开

错误码

说明

200

通用错误。

示例代码

收起
自动换行
深色代码主题
复制
  1. device.getCountryCode({
  2. success: function (ret){
  3. console.log(`countryCode = ${ret.countryCode}`)
  4. },
  5. fail: function(erromsg, errocode){
  6. console.log(`error message = ${erromsg}, error code = ${errocode}`)
  7. },
  8. complete: function () {
  9. prompt.showToast({
  10. message: "请求完成"
  11. })
  12. }
  13. })

device.toLocaleDateTimeString(timeStamp)(1072+,非厂商联盟规范)

描述

将时间戳转换为和系统日期、时间格式相同的字符串。

说明

该方法为同步方法。

参数

展开

参数

类型

是否必填

说明

timeStamp

number

是

标准时间戳。

返回值

展开

参数

类型

说明

-

string

返回与系统日期、时间格式一致的字符串,包含日期和时间两部分信息。

示例代码

收起
自动换行
深色代码主题
复制
  1. console.log(device.toLocaleDateTimeString(123456))

device.toLocaleDateString(timeStamp)(1072+,非厂商联盟规范)

描述

将时间戳转换为和系统日期格式相同的字符串。

说明

该方法为同步方法。

参数

展开

参数

类型

是否必填

说明

timeStamp

number

是

标准时间戳。

返回值

展开

参数

类型

说明

-

string

返回与系统日期、时间格式一致的字符串,包含日期和时间两部分信息。

示例代码

收起
自动换行
深色代码主题
复制
  1. console.log(device.toLocaleDateString(123456))

device.toLocaleTimeString(timeStamp)(1072+,非厂商联盟规范)

描述

将时间戳转换为和系统日期格式相同的字符串。

说明

该方法为同步方法。

参数

展开

参数

类型

是否必填

说明

timeStamp

number

是

标准时间戳。

返回值

展开

参数

类型

说明

-

string

返回与系统日期、时间格式一致的字符串,包含日期和时间两部分信息。

示例代码

收起
自动换行
深色代码主题
复制
  1. console.log(device.toLocaleTimeString(123456))

device.host(OBJECT)(1070+)

描述

获取宿主应用包名、版本号、版本名。快应用场景返回加载器或快应用中心的信息,卡片返回卡片宿主apk的信息。

OBJECT参数

展开

参数

类型

是否必填

说明

success

function

否

成功回调。

fail

function

否

失败回调。

complete

function

否

执行结束后的回调。

success返回值

展开

参数

类型

说明

package

string

宿主应用的包名。

versionCode

number

宿主应用的版本号。

versionName

string

宿主应用的版本名称。

fail返回值

展开

错误码

说明

203

服务不可用。

示例代码

收起
自动换行
深色代码主题
复制
  1. device.host({
  2. success: function (ret) {
  3. console.log("handling success: " + JSON.stringify(ret));
  4. },
  5. fail: function (erromsg, errocode) {
  6. console.log("handling success: " + errocode + ': ' + erromsg)
  7. },
  8. })

device.getCarNo(OBJECT)(1079+,非厂商联盟规范)

描述

获取车牌号,需弹框获取用户授权。

OBJECT参数

展开

参数

类型

是否必填

说明

success

function

否

成功回调。

fail

function

否

失败回调。

complete

function

否

执行结束后的回调。

success返回值:

展开

参数

类型

说明

carNo

string

车牌号。

fail返回值:

展开

错误码

说明

201

用户拒绝授权。

205

该车机不支持。

示例代码

收起
自动换行
深色代码主题
复制
  1. device.getCarNo({
  2. success: function (ret) {
  3. that.CarNo = JSON.stringify(ret);
  4. },
  5. fail: function (erromsg, errocode) {
  6. that.CarNo = errocode + ': ' + erromsg
  7. },
  8. complete: function () {
  9. prompt.showToast({
  10. message: "请求完成"
  11. })
  12. }
  13. })

device.getCarInfoVin(OBJECT)(1079+,非厂商联盟规范)

描述

获取车架号,需弹框获取用户授权。

OBJECT参数

展开

参数

类型

是否必填

说明

success

function

否

成功回调。

fail

function

否

失败回调。

complete

function

否

执行结束后的回调。

success返回值:

展开

参数

类型

说明

carInfoVin

string

车架号。

fail返回值:

展开

错误码

说明

201

用户拒绝授权。

示例代码

收起
自动换行
深色代码主题
复制
  1. device.getCarInfoVin({
  2. success: function (ret) {
  3. that.InfoVin = JSON.stringify(ret);
  4. },
  5. fail: function (erromsg, errocode) {
  6. that.InfoVin = errocode + ': ' + erromsg
  7. },
  8. complete: function () {
  9. prompt.showToast({
  10. message: "请求完成"
  11. })
  12. }
  13. })

device.getCarEngineNo(OBJECT)(1079+,非厂商联盟规范)

描述

获取发动机号,需弹框获取用户授权。

OBJECT参数

展开

参数

类型

是否必填

说明

success

function

否

成功回调。

fail

function

否

失败回调。

complete

function

否

执行结束后的回调。

success返回值:

展开

参数

类型

说明

engineNo

string

发动机号。

fail返回值:

展开

错误码

说明

201

用户拒绝授权。

205

该车机不支持。

示例代码

收起
自动换行
深色代码主题
复制
  1. device.getCarEngineNo({
  2. success: function (ret) {
  3. that.EngineNo = JSON.stringify(ret);
  4. },
  5. fail: function (erromsg, errocode) {
  6. that.EngineNo = errocode + ': ' + erromsg
  7. },
  8. complete: function () {
  9. prompt.showToast({
  10. message: "请求完成"
  11. })
  12. }
  13. })

device.getCarNoColor(OBJECT)(1079+,非厂商联盟规范)

描述

获取车牌颜色。

OBJECT参数

展开

参数

类型

是否必填

说明

success

function

否

成功回调。

fail

function

否

失败回调。

complete

function

否

执行结束后的回调。

success返回值:

展开

参数

类型

说明

carNoColor

number

车牌颜色。

fail返回值:

展开

错误码

说明

205

该车机不支持。

示例代码

收起
自动换行
深色代码主题
复制
  1. device.getCarNoColor({
  2. success: function (ret) {
  3. that.CarNoColor = JSON.stringify(ret);
  4. },
  5. fail: function (erromsg, errocode) {
  6. that.CarNoColor = errocode + ': ' + erromsg
  7. },
  8. complete: function () {
  9. prompt.showToast({
  10. message: "请求完成"
  11. })
  12. }
  13. })

device.getCarRegisterTime(OBJECT)(1079+,非厂商联盟规范)

描述

获取车辆注册日期。

OBJECT参数

展开

参数

类型

是否必填

说明

success

function

否

成功回调。

fail

function

否

失败回调。

complete

function

否

执行结束后的回调。

success返回值:

展开

参数

类型

说明

registerTime

number

车辆注册日期。

fail返回值:

展开

错误码

说明

205

该车机不支持。

示例代码

收起
自动换行
深色代码主题
复制
  1. device.getCarRegisterTime({
  2. success: function (ret) {
  3. that.RegisterTime = JSON.stringify(ret);
  4. },
  5. fail: function (erromsg, errocode) {
  6. that.RegisterTime = errocode + ': ' + erromsg
  7. },
  8. complete: function () {
  9. prompt.showToast({
  10. message: "请求完成"
  11. })
  12. }
  13. })

device.getCarSeatsCount(OBJECT)(1079+,非厂商联盟规范)

描述

获取车辆座位数。

OBJECT参数

展开

参数

类型

是否必填

说明

success

function

否

成功回调。

fail

function

否

失败回调。

complete

function

否

执行结束后的回调。

success返回值:

展开

参数

类型

说明

seatsCount

string

车牌座位数。

fail返回值:

展开

错误码

说明

205

该车机不支持。

示例代码

收起
自动换行
深色代码主题
复制
  1. device.getCarSeatsCount({
  2. success: function (ret) {
  3. that.SeatsCount = JSON.stringify(ret);
  4. },
  5. fail: function (erromsg, errocode) {
  6. that.SeatsCount = errocode + ': ' + erromsg
  7. },
  8. complete: function () {
  9. prompt.showToast({
  10. message: "请求完成"
  11. })
  12. }
  13. })

device.getCarInfoModel(OBJECT)(1079+,非厂商联盟规范)

描述

获取车辆型号。

OBJECT参数

展开

参数

类型

是否必填

说明

success

function

否

成功回调。

fail

function

否

失败回调。

complete

function

否

执行结束后的回调。

success返回值:

展开

参数

类型

说明

infoModel

string

车辆型号。

示例代码

收起
自动换行
深色代码主题
复制
  1. device.getCarInfoModel({
  2. success: function (ret) {
  3. that.InfoModel = JSON.stringify(ret);
  4. },
  5. fail: function (erromsg, errocode) {
  6. that.InfoModel = errocode + ': ' + erromsg
  7. },
  8. complete: function () {
  9. prompt.showToast({
  10. message: "请求完成"
  11. })
  12. }
  13. })

device.getCarInfoModelYear(OBJECT)(1079+,非厂商联盟规范)

描述

获取车型年份。

OBJECT参数

展开

参数

类型

是否必填

说明

success

function

否

成功回调。

fail

function

否

失败回调。

complete

function

否

执行结束后的回调。

success返回值:

展开

参数

类型

说明

infoModelYear

string

车型的年份。

示例代码

收起
自动换行
深色代码主题
复制
  1. device.getCarInfoModelYear({
  2. success: function (ret) {
  3. that.InfoModelYear = JSON.stringify(ret);
  4. },
  5. fail: function (erromsg, errocode) {
  6. that.InfoModelYear = errocode + ': ' + erromsg
  7. },
  8. complete: function () {
  9. prompt.showToast({
  10. message: "请求完成"
  11. })
  12. }
  13. })

device.getCarManufacturer(OBJECT)(1079+,非厂商联盟规范)

描述

获取车辆制造商。

OBJECT参数

展开

参数

类型

是否必填

说明

success

function

否

成功回调。

fail

function

否

失败回调。

complete

function

否

执行结束后的回调。

success返回值:

展开

参数

类型

说明

manufacturer

string

车辆制造商。

示例代码

收起
自动换行
深色代码主题
复制
  1. device.getCarManufacturer({
  2. success: function (ret) {
  3. that.Manufacturer = JSON.stringify(ret);
  4. },
  5. fail: function (erromsg, errocode) {
  6. that.Manufacturer = errocode + ': ' + erromsg
  7. },
  8. complete: function () {
  9. prompt.showToast({
  10. message: "请求完成"
  11. })
  12. }
  13. })

device.isFoldable()(1083+)

描述

检测设备是否为可折叠设备。

返回值

展开

返回值

说明

true

该设备是可折叠设备。

false

该设备不是可折叠设备。

示例代码

收起
自动换行
深色代码主题
复制
  1. const isFoldable = device.isFoldable();
  2. console.log('isFoldable ', isFoldable);

device.isCodecSupported(codecName)(1110+)

描述

检查设备是否支持指定参数的编解码器。

OBJECT参数

展开

参数

类型

是否必填

说明

codecName

string

Mandatory

参数取值:h264、h265、h266 。

success返回值:

展开

参数

类型

说明

-

boolean

返回一个布尔值,表示设备是否支持指定参数的编解码器。

true:支持

false:不支持

示例代码

收起
自动换行
深色代码主题
复制
  1. console.log(device.isCodecSupported('h264'))

Demo

收起
自动换行
深色代码主题
复制
  1. <template>
  2. <div class="container">
  3. <div class="item-container">
  4. <div class="item-content">
  5. <text>pageGetInfo:</text>
  6. <text>{{pageInfo}}</text>
  7. </div>
  8. <input type="button" class="btn" onclick="getPageInfo" value="getInfoByPage" />
  9. </div>
  10. <div class="item-container">
  11. <div class="item-content">
  12. <text>anti-screenshot:</text>
  13. <text>anti-screenshotStatus:{{isSecure}}</text>
  14. </div>
  15. <input type="button" class="btn" onclick="changeSecure" value="setSecure" />
  16. </div>
  17. <div class="item-container">
  18. <div class="item-content">
  19. <text>deviceInfo:</text>
  20. <text>{{deviceInfo}}</text>
  21. </div>
  22. <input type="button" class="btn" onclick="getDeviceInfo" value="getDeviceInfo" />
  23. </div>
  24. <div class="item-container">
  25. <div class="item-content">
  26. <text>deviceInfoSync:</text>
  27. <text>{{deviceInfoSync}}</text>
  28. </div>
  29. <input type="button" class="btn" onclick="getDeviceInfoSync" value="getDeviceInfoSync" />
  30. </div>
  31. <div class="item-container">
  32. <div class="item-content">
  33. <text>device.id:</text>
  34. <text>{{id}}</text>
  35. </div>
  36. <input type="button" class="btn" onclick="getId" value="getId" />
  37. </div>
  38. <div class="item-container">
  39. <div class="item-content">
  40. <text>deviceId:</text>
  41. <text>{{deviceId}}</text>
  42. </div>
  43. <input type="button" class="btn" onclick="getDeviceId" value="getDeviceId" />
  44. </div>
  45. <div class="item-container">
  46. <div class="item-content">
  47. <text>deviceOAID:</text>
  48. <text>{{OAID}}</text>
  49. </div>
  50. <input type="button" class="btn" onclick="getOAID" value="getDeviceOAID" />
  51. </div>
  52. <div class="item-container">
  53. <div class="item-content">
  54. <text>CountryCode:</text>
  55. <text>{{CountryCode}}</text>
  56. </div>
  57. <input type="button" class="btn" onclick="getCountryCode" value="getCountryCode" />
  58. </div>
  59. <div class="item-container">
  60. <div class="item-content">
  61. <text>serviceCountryCode:</text>
  62. <text>{{serviceCountryCode}}</text>
  63. </div>
  64. <input type="button" class="btn" onclick="getServiceCountryCode" value="getServiceCountryCode" />
  65. </div>
  66. <div class="item-container">
  67. <div class="item-content">
  68. <text>deviceUserId:</text>
  69. <text>{{userId}}</text>
  70. </div>
  71. <input type="button" class="btn" onclick="getUserId" value="getUserId" />
  72. </div>
  73. <div class="item-container">
  74. <div class="item-content">
  75. <text>totalStorage:</text>
  76. <text>{{totalStorage}}</text>
  77. </div>
  78. <input type="button" class="btn" onclick="getTotalStorage" value="getTotalStorage" />
  79. </div>
  80. <div class="item-container">
  81. <div class="item-content">
  82. <text>availableStorage:</text>
  83. <text>{{availableStorage}}</text>
  84. </div>
  85. <input type="button" class="btn" onclick="getAvailableStorage" value="getAvailableStorage" />
  86. </div>
  87. <div class="item-container">
  88. <div class="item-content">
  89. <text>cpuInfo:</text>
  90. <text>{{cpuInfo}}</text>
  91. </div>
  92. <input type="button" class="btn" onclick="getCpuInfo" value="getCpuInfo" />
  93. </div>
  94. <div class="item-container">
  95. <div class="item-content">
  96. <text>device.serial:</text>
  97. <text>{{SNinfo}}</text>
  98. </div>
  99. <input type="button" class="btn" onclick="getSerial" value="getSerial" />
  100. </div>
  101. <div class="item-container">
  102. <div class="item-content">
  103. <text>hostinfo:</text>
  104. <text>{{hostInfo}}</text>
  105. </div>
  106. <input type="button" class="btn" onclick="getHost" value="getHostinfo" />
  107. </div>
  108. <div class="item-container">
  109. <div class="item-content">
  110. <text>localedatetime:</text>
  111. <text>{{localeDateTimeString}}</text>
  112. </div>
  113. <input type="button" class="btn" onclick="tolocaleDateTimeString" value="getLocaleDateTime" />
  114. </div>
  115. <div class="item-container">
  116. <div class="item-content">
  117. <text>localedate:</text>
  118. <text>{{localeDateString}}</text>
  119. </div>
  120. <input type="button" class="btn" onclick="tolocaleDateString" value="getLocaleDate" />
  121. </div>
  122. <div class="item-container">
  123. <div class="item-content">
  124. <text>localetime:</text>
  125. <text>{{localeTimeString}}</text>
  126. </div>
  127. <input type="button" class="btn" onclick="tolocaleTimeString" value="getLocaleTime" />
  128. </div>
  129. </div>
  130. </template>
  131. <style>
  132. .container {
  133. flex: 1;
  134. flex-direction: column;
  135. }
  136. .item-container {
  137. margin-bottom: 50px;
  138. margin-right: 60px;
  139. margin-left: 60px;
  140. flex-direction: column;
  141. }
  142. .item-content {
  143. flex-direction: column;
  144. padding: 30px;
  145. margin-bottom: 50px;
  146. align-items: flex-start;
  147. }
  148. .btn {
  149. height: 80px;
  150. text-align: center;
  151. border-radius: 5px;
  152. margin-right: 60px;
  153. margin-left: 60px;
  154. margin-bottom: 50px;
  155. color: #ffffff;
  156. font-size: 30px;
  157. background-color: #0faeff;
  158. }
  159. </style>
  160. <script>
  161. import device from '@system.device'
  162. import prompt from '@system.prompt'
  163. export default {
  164. data: {
  165. deviceInfo: '',
  166. themeInfo: '',
  167. deviceInfoSync: '',
  168. themeInfoSync: '',
  169. id: '',
  170. deviceId: '',
  171. OAID: '',
  172. userId: '',
  173. serviceCountryCode: '',
  174. CountryCode: '',
  175. totalStorage: '',
  176. availableStorage: '',
  177. cpuInfo: '',
  178. SNinfo: '',
  179. pageInfo: '',
  180. hostInfo: '',
  181. isSecure: false,
  182. localeDateTimeString: '',
  183. localeDateString: '',
  184. localeTimeString: ''
  185. },
  186. onInit() {
  187. this.$page.setTitleBar({ text: 'device' })
  188. device.onFontScaleChange({
  189. callback: function (ret) {
  190. console.log('fontScale ==' + ret.fontScale)
  191. prompt.showToast({
  192. message: 'fontScale ==' + ret.fontScale
  193. })
  194. }
  195. })
  196. },
  197. getPageInfo: function () {
  198. this.pageInfo = 'windowHeight = ' + this.$page.windowHeight
  199. + ' windowWidth = ' + this.$page.windowWidth
  200. + ' statusBarHeight = ' + this.$page.statusBarHeight
  201. },
  202. changeSecure: function () {
  203. this.isSecure = !this.isSecure
  204. this.$page.setSecure(this.isSecure)
  205. },
  206. getDeviceInfo: function () {
  207. var that = this
  208. device.getInfo({
  209. success: function (ret) {
  210. that.deviceInfo = JSON.stringify(ret)
  211. },
  212. fail: function (erromsg, errocode) {
  213. that.deviceInfo = errocode + ': ' + erromsg
  214. },
  215. complete: function () {
  216. prompt.showToast({
  217. message: "requestSuccess"
  218. })
  219. }
  220. })
  221. },
  222. getDeviceInfoSync: function () {
  223. try {
  224. var info = device.getInfoSync()
  225. this.deviceInfoSync = JSON.stringify(info)
  226. } catch (e) { }
  227. },
  228. getId: function () {
  229. var that = this
  230. device.getId({
  231. type: ['device', 'mac', 'user'],
  232. success: function (ret) {
  233. that.id = JSON.stringify(ret)
  234. },
  235. fail: function (erromsg, errocode) {
  236. that.id = errocode + ': ' + erromsg
  237. },
  238. complete: function () {
  239. prompt.showToast({
  240. message: "request Success"
  241. })
  242. }
  243. })
  244. },
  245. getDeviceId: function () {
  246. var that = this
  247. device.getDeviceId({
  248. success: function (ret) {
  249. that.deviceId = JSON.stringify(ret)
  250. },
  251. fail: function (erromsg, errocode) {
  252. that.deviceId = errocode + ': ' + erromsg
  253. },
  254. complete: function () {
  255. prompt.showToast({
  256. message: "request Success"
  257. })
  258. }
  259. })
  260. },
  261. getServiceCountryCode: function () {
  262. var that = this
  263. device.getServiceCountryCode({
  264. success: function (ret) {
  265. that.serviceCountryCode = ret.serviceCountryCode
  266. },
  267. fail: function (erromsg, errocode) {
  268. that.serviceCountryCode = errocode + ': ' + erromsg
  269. },
  270. complete: function () {
  271. prompt.showToast({
  272. message: 'getServiceCountryCode success'
  273. })
  274. }
  275. })
  276. },
  277. getCountryCode: function () {
  278. var that = this
  279. device.getCountryCode({
  280. success: function (ret) {
  281. that.CountryCode = ret.countryCode
  282. },
  283. fail: function (erromsg, errocode) {
  284. that.CountryCode = errocode + ': ' + erromsg
  285. },
  286. complete: function () {
  287. prompt.showToast({
  288. message: 'getCountryCode success'
  289. })
  290. }
  291. })
  292. },
  293. getOAID: function () {
  294. var that = this
  295. device.getOAID({
  296. success: function (ret) {
  297. that.OAID = JSON.stringify(ret)
  298. },
  299. fail: function (erromsg, errocode) {
  300. that.OAID = errocode + ': ' + erromsg
  301. },
  302. complete: function () {
  303. console.log("message" + device.platform.versionCode);
  304. prompt.showToast({
  305. message: 'getOAID ' + device.allowTrackOAID
  306. })
  307. }
  308. })
  309. },
  310. getUserId: function () {
  311. var that = this
  312. device.getUserId({
  313. success: function (ret) {
  314. that.userId = JSON.stringify(ret)
  315. },
  316. fail: function (erromsg, errocode) {
  317. that.userId = errocode + ': ' + erromsg
  318. },
  319. complete: function () {
  320. prompt.showToast({
  321. message: "request Success"
  322. })
  323. }
  324. })
  325. },
  326. getTotalStorage: function () {
  327. var that = this
  328. device.getTotalStorage({
  329. success: function (ret) {
  330. that.totalStorage = JSON.stringify(ret)
  331. },
  332. fail: function (erromsg, errocode) {
  333. that.totalStorage = errocode + ': ' + erromsg
  334. },
  335. complete: function () {
  336. prompt.showToast({
  337. message: "request Success"
  338. })
  339. }
  340. })
  341. },
  342. getAvailableStorage: function () {
  343. var that = this
  344. device.getAvailableStorage({
  345. success: function (ret) {
  346. that.availableStorage = JSON.stringify(ret)
  347. },
  348. fail: function (erromsg, errocode) {
  349. that.availableStorage = errocode + ': ' + erromsg
  350. },
  351. complete: function () {
  352. prompt.showToast({
  353. message: "requestSuccess"
  354. })
  355. }
  356. })
  357. },
  358. getCpuInfo: function () {
  359. var that = this
  360. device.getCpuInfo({
  361. success: function (ret) {
  362. that.cpuInfo = JSON.stringify(ret)
  363. },
  364. fail: function (erromsg, errocode) {
  365. that.cpuInfo = errocode + ': ' + erromsg
  366. },
  367. complete: function () {
  368. prompt.showToast({
  369. message: "request Success"
  370. })
  371. }
  372. })
  373. },
  374. getSerial: function () {
  375. var that = this
  376. device.getSerial({
  377. success: function (ret) {
  378. that.SNinfo = JSON.stringify(ret)
  379. },
  380. fail: function (erromsg, errocode) {
  381. that.SNinfo = errocode + ': ' + erromsg
  382. },
  383. complete: function () {
  384. prompt.showToast({
  385. message: "request Success"
  386. })
  387. }
  388. })
  389. },
  390. getHost: function () {
  391. var that = this
  392. device.host({
  393. success: function (ret) {
  394. console.log('host succ data:' + JSON.stringify(ret))
  395. that.hostInfo = JSON.stringify(ret)
  396. },
  397. fail: function (erromsg, errocode) {
  398. that.hostInfo = errocode + ': ' + erromsg
  399. },
  400. complete: function () {
  401. prompt.showToast({
  402. message: "requestSuccess"
  403. })
  404. }
  405. })
  406. },
  407. tolocaleDateTimeString: function () {
  408. this.localeDateTimeString = device.toLocaleDateTimeString(12345678910)
  409. },
  410. tolocaleDateString: function () {
  411. this.localeDateString = device.toLocaleDateString(100000000)
  412. },
  413. tolocaleTimeString: function () {
  414. this.localeTimeString = device.toLocaleTimeString(100000000)
  415. }
  416. }
  417. </script>

效果图如下:

版本更新说明

展开

版本

发布日期

描述

1110

2024-02-07

  • 新增device.isCodecSupported(codecName)方法,用于检查设备是否支持指定参数的编解码器。
  • device.getInfo接口的deviceType参数新增取值foldable,表示可折叠设备。

1100

2022-07-07

接口device.getInfo的返回值新增screenRefreshRate字段,获取屏幕当前显示的刷新率。

1090

2022-05-19

在device.getInfo(OBJECT)接口中新增返回deviceType参数。

1083

2022-03-21

新增isFoldable方法,用于检测设备是否为可折叠设备。

1080

2021-12-28

在device.getInfo(OBJECT)接口中新增返回vendorOsName和vendorOsVersion参数。

1070

2020-05-19

  • 新增getCountryCode方法,用于获取当前快应用中心华为账号的注册国家地信息。
  • 新增host方法,用于获取宿主应用的信息。

1060

2019-12-10

  • device.getInfo和device.getInfoSync增加marketingName返回,以方便用户获取机型传播名。
  • 新增getServiceCountryCode接口获取服务地。

1050

2019-09-20

  • 新增device.getSerial,可获取设备序列号。device.getId、device.getDeviceId、device.getUserId 在系统版本号为10.0及以上将无法获取数据。
  • device.getInfo 新增 emuiApiLevel,获取系统的api版本号。

1040

2019-06-24

  • device.getInfo的success回调返回值增加返回screenDensity信息。
  • device.getInfo增加返回timeZone、emuiVer、fontScale、characteristics、windowLogicWidth、windowLogicHeight信息。
  • 新增getInfoSync、onFontScaleChange接口。

1030

2018-10-31

新增platform对象,通过该对象的versionCode属性,可以获取平台的版本号。

1020

2018-06-20

device.getInfo(OBJECT)接口新增 windowWidth、windowHeight、statusBarHeight和pixelRatio 4个返回值。

相关链接