在调用接口页面的<script>部分增加如下配置。
import device from '@system.device'
或
var device = require("@system.device") | 属性 | 类型 | 默认值 | 是否必选 | 说明 |
|---|---|---|---|---|
| platform | object | - | 否 | 用于获取平台信息,该对象包括一个属性值:versionCode,表示平台版本号。 |
| allowTrackOAID(1060+) | boolean | - | 否 | 限制oaid以及HarmonyOS 2.0及以上或Android 10.0及以上的deviceId是否可以用于广告跟踪。设置为true,表示限制用于广告跟踪。该值的更新需要引擎进程重启后生效,否则读取的为引擎缓存的值。 |
| 接口 | 描述 |
|---|---|
| 获取设备信息。 | |
| 获取设备信息。 | |
| 获取设备Id。 | |
| 获取设备唯一标识,需要用户授权。 | |
| 获取用户唯一标识。 | |
| 获取匿名设备标识符,建议只在广告的场景使用。 | |
| 获取内部存储空间的总大小,不计算外置sdcard的存储空间。 | |
| 获取内部存储空间的可用大小,不计算外置sdcard的可用大小。 | |
| 返回CPU信息。 | |
| 监听系统字体设置比例的改变,当系统字体设置改变时,触发callback回调。在卡片的环境下由宿主应用监听到变化后,通过onConfigurationChanged(Configuration newConfig)通知到fastview sdk,fastview sdk负责事件onFontScaleChange的回调。 | |
| 返回当前快应用中心的服务地信息,目前服务地为海外时有些能力不可用,比如微信分享,支付,支付宝支付,微博分享等能力,此接口返回的值不一定与操作系统设置的国家码相同。 | |
| 获取当前快应用中心华为账号的注册国家地信息。 | |
| 将时间戳转换为和系统日期、时间格式相同的字符串。 | |
| 将时间戳转换为和系统日期格式相同的字符串。 | |
| 将时间戳转换为和系统日期格式相同的字符串。 | |
| 获取宿主应用的包名、版本号和版本名。 | |
| 获取车牌号,需要用户授权。 | |
| 获取车架号,需要用户授权。 | |
| 获取发动机号,需要用户授权。 | |
| 获取车牌颜色。 | |
| 获取车辆注册日期。 | |
| 获取车辆座位数。 | |
| 获取车辆型号。 | |
| 获取车型年份。 | |
| 获取车辆制造商。 | |
| 检测设备是否为可折叠设备。 | |
| 检查设备是否支持指定参数的编解码器。 |
描述
获取设备信息。
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 | 针对异形屏(比如刘海屏、水滴屏和开孔屏),返回异形区域的位置。包含以下参数:
例如: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 |
|
| 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 | 设备类型。 取值如下:
|
| screenRefreshRate(1100+) | float | 屏幕当前显示的刷新率。 获得的帧率可能不是60、90、144等标准帧率值。 |
示例代码
device.getInfo({
success: function (ret) {
console.log("handling success:",JSON.stringify(ret));
},
fail: function (erromsg, errocode) {
console.log("message:",erromsg,errocode);
}
}) 输出结果如下:
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": "" }
描述
获取设备信息。
返回值
| 参数名 | 类型 | 说明 |
|---|---|---|
| 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 |
|
| windowLogicHeight(1040+) | number | 在卡片场景下特有,以750为基准,卡片宿主应用为卡片显示分配的高度。如果宿主应用没有给卡片分配特定的高度,获取此值将失败。 |
| emuiApiLevel(1050+) | string | 系统的api版本号,如18。 |
| marketingName(1060+) | string | 机型传播名,如P20Pro。 |
| harmonyOSVer(1078+) | string | HarmonyOS设备版本号,如2.0.0。 |
示例代码
try {
const res = device.getInfoSync();
console.log(res.brand);
console.log(res.model);
} catch (e) {
// Do something when catch error
console.log(e.code + e.message);
} 描述
获取设备标识、用户标识、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及以上版本返回值和快应用签名值相关,相同的签名值相同。如下情况将导致获取值发生改变:
|
fail返回错误码:
| 错误码 | 说明 |
|---|---|
| 201 | 用户拒绝,获取电话状态权限失败。 |
示例代码
device.getId({
type: ["device", "mac"],
success:function(data) {
console.log("handling success: " + data.device);
},
fail: function(data, code) {
console.log("handling fail, code=" + code);
}
}) 描述
获取设备标识。
智慧屏和卡片不支持。
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 | 用户拒绝授权。 |
示例代码
device.getDeviceId({
success: function(data) {
console.log("handling success: " + data.deviceId);
},
fail: function(data, code) {
console.log("handling fail, code=" + code);
}
}) 描述
获取用户标识。
智慧屏和卡片不支持。
无弹框授权。
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个字符。如下情况将导致获取值发生改变:
|
示例代码
device.getUserId({
success: function(data) {
console.log("handling success: " + data.userId);
},
fail: function(data, code) {
console.log("handling fail, code=" + code);
}
}) 描述
获取匿名设备标识符,建议只在广告的场景使用。
智慧屏、车机和卡片不支持。
OBJECT参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| success | function | 否 | 成功回调。 |
| fail | function | 否 | 失败回调。 |
| complete | function | 否 | 执行结束后的回调。 |
success返回值:
| 参数名 | 类型 | 说明 |
|---|---|---|
| oaid | string | 匿名设备标识符。如果当前设备不支持oaid,返回空值。当用户重置广告标识符后,该值发生改变。当手机系统设置项“限制广告跟踪”为开启状态时,返回由0组成的字符串。 |
示例代码
device.getOAID({
success: function (ret) {
that.OAID = JSON.stringify(ret);
},
fail: function (erromsg, errocode) {
that.OAID = errocode + ': ' + erromsg
},
complete: function () {
prompt.showToast({
message: "请求完成" + device.allowTrackOAID
})
}
}) 描述
获取内部存储空间的总大小,不计算外置sdcard的存储空间。
OBJECT参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| success | function | 否 | 成功回调。 |
| fail | function | 否 | 失败回调。 |
| complete | function | 否 | 执行结束后的回调。 |
success返回值:
| 参数名 | 类型 | 说明 |
|---|---|---|
| totalStorage | long | 存储空间的总大小,单位是Byte。在Android上返回的是外部存储的总大小。 |
示例代码
device.getTotalStorage({
success:function(data) {
console.log("handling success: " + data.totalStorage);
},
fail: function(data, code) {
console.log("handling fail, code=" + code);
}
}) 描述
获取内部存储空间的可用大小,不计算外置sdcard的可用大小。
OBJECT参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| success | function | 否 | 成功回调。 |
| fail | function | 否 | 失败回调。 |
| complete | function | 否 | 执行结束后的回调。 |
success返回值:
| 参数名 | 类型 | 说明 |
|---|---|---|
| availableStorage | long | 存储空间的可用大小,单位是Byte。在Android上返回的是外部存储的可用大小。 |
示例代码
device.getAvailableStorage({
success:function(data) {
console.log("handling success: " + data.availableStorage);
},
fail: function(data, code) {
console.log("handling fail, code=" + code);
}
}) 描述
返回CPU信息。
OBJECT参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| success | function | 否 | 成功回调。 |
| fail | function | 否 | 失败回调。 |
| complete | function | 否 | 执行结束后的回调。 |
success返回值:
| 参数名 | 类型 | 说明 |
|---|---|---|
| cpuInfo | string | CPU信息。在Android上返回的是/proc/cpuinfo文件的内容。 |
示例代码
device.getCpuInfo({
success:function(data) {
console.log("handling success: " + data.cpuInfo);
},
fail: function(data, code) {
console.log("handling fail, code=" + code);
}
}) 描述
监听系统字体设置比例的改变,当系统字体设置改变时,触发callback回调。在卡片的环境下由宿主应用监听到变化后,通过onConfigurationChanged(Configuration newConfig)通知到fastview sdk,fastview sdk负责事件onFontScaleChange的回调。
OBJECT参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| callback | function | 否 | 每次系统字体设置的比例发生变化,会被回调。 |
callback返回值:
| 参数名 | 类型 | 说明 |
|---|---|---|
| fontScale | number | 用户字体大小设置。以“系统-设置-通用-字体大小”中的设置为准,例如0.9, 1,1.1,1.2,1.5等。 |
示例代码
device.onFontScaleChange({
callback: function(ret) {
console.log("fontScale ==" + ret.fontScale);
}
}) 描述
返回当前快应用中心的服务地信息,目前服务地为海外时有些能力不可用,比如微信分享,支付,支付宝支付,微博分享等能力,此接口返回的值不一定与操作系统设置的国家码相同。
OBJECT参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| success | function | 否 | 成功回调。 |
| fail | function | 否 | 失败回调。 |
| complete | function | 否 | 执行结束后的回调。 |
success返回值:
| 参数 | 类型 | 说明 |
|---|---|---|
| serviceCountryCode | string | 返回当前快应用中心的服务地信息,符合 ISO 3166 标准,如CN,JP。 |
fail返回错误码:
| 错误码 | 说明 |
|---|---|
| 200 | 通用错误。 |
示例代码
device.getServiceCountryCode({
success: function (ret){
console.log(`serviceCountryCode = ${ret.serviceCountryCode}`)
},
fail: function(erromsg, errocode){
console.log(`error message = ${erromsg}, error code = ${errocode}`)
},
complete: function () {
prompt.showToast({
message: "请求完成"
})
}
}) 描述
获取当前快应用中心华为账号的注册国家地信息。
使用华为加载器调试时,无法获取对应信息。
OBJECT参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| success | function | 否 | 成功回调。 |
| fail | function | 否 | 失败回调。 |
| complete | function | 否 | 执行结束后的回调。 |
success返回值:
| 参数 | 类型 | 说明 |
|---|---|---|
| countryCode | string | 返回当前快应用中心的服务地信息,符合 ISO 3166 标准,如CN,JP。 |
fail返回错误码:
| 错误码 | 说明 |
|---|---|
| 200 | 通用错误。 |
示例代码
device.getCountryCode({
success: function (ret){
console.log(`countryCode = ${ret.countryCode}`)
},
fail: function(erromsg, errocode){
console.log(`error message = ${erromsg}, error code = ${errocode}`)
},
complete: function () {
prompt.showToast({
message: "请求完成"
})
}
}) 描述
将时间戳转换为和系统日期、时间格式相同的字符串。
该方法为同步方法。
参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| timeStamp | number | 是 | 标准时间戳。 |
返回值
| 参数 | 类型 | 说明 |
|---|---|---|
| - | string | 返回与系统日期、时间格式一致的字符串,包含日期和时间两部分信息。 |
示例代码
console.log(device.toLocaleDateTimeString(123456))
描述
将时间戳转换为和系统日期格式相同的字符串。
该方法为同步方法。
参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| timeStamp | number | 是 | 标准时间戳。 |
返回值
| 参数 | 类型 | 说明 |
|---|---|---|
| - | string | 返回与系统日期、时间格式一致的字符串,包含日期和时间两部分信息。 |
示例代码
console.log(device.toLocaleDateString(123456))
描述
将时间戳转换为和系统日期格式相同的字符串。
该方法为同步方法。
参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| timeStamp | number | 是 | 标准时间戳。 |
返回值
| 参数 | 类型 | 说明 |
|---|---|---|
| - | string | 返回与系统日期、时间格式一致的字符串,包含日期和时间两部分信息。 |
示例代码
console.log(device.toLocaleTimeString(123456))
描述
获取宿主应用包名、版本号、版本名。快应用场景返回加载器或快应用中心的信息,卡片返回卡片宿主apk的信息。
OBJECT参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| success | function | 否 | 成功回调。 |
| fail | function | 否 | 失败回调。 |
| complete | function | 否 | 执行结束后的回调。 |
success返回值
| 参数 | 类型 | 说明 |
|---|---|---|
| package | string | 宿主应用的包名。 |
| versionCode | number | 宿主应用的版本号。 |
| versionName | string | 宿主应用的版本名称。 |
fail返回值
| 错误码 | 说明 |
|---|---|
| 203 | 服务不可用。 |
示例代码
device.host({
success: function (ret) {
console.log("handling success: " + JSON.stringify(ret));
},
fail: function (erromsg, errocode) {
console.log("handling success: " + errocode + ': ' + erromsg)
},
}) 描述
获取车牌号,需弹框获取用户授权。
OBJECT参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| success | function | 否 | 成功回调。 |
| fail | function | 否 | 失败回调。 |
| complete | function | 否 | 执行结束后的回调。 |
success返回值:
| 参数 | 类型 | 说明 |
|---|---|---|
| carNo | string | 车牌号。 |
fail返回值:
| 错误码 | 说明 |
|---|---|
| 201 | 用户拒绝授权。 |
| 205 | 该车机不支持。 |
示例代码
device.getCarNo({
success: function (ret) {
that.CarNo = JSON.stringify(ret);
},
fail: function (erromsg, errocode) {
that.CarNo = errocode + ': ' + erromsg
},
complete: function () {
prompt.showToast({
message: "请求完成"
})
}
}) 描述
获取车架号,需弹框获取用户授权。
OBJECT参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| success | function | 否 | 成功回调。 |
| fail | function | 否 | 失败回调。 |
| complete | function | 否 | 执行结束后的回调。 |
success返回值:
| 参数 | 类型 | 说明 |
|---|---|---|
| carInfoVin | string | 车架号。 |
fail返回值:
| 错误码 | 说明 |
|---|---|
| 201 | 用户拒绝授权。 |
示例代码
device.getCarInfoVin({
success: function (ret) {
that.InfoVin = JSON.stringify(ret);
},
fail: function (erromsg, errocode) {
that.InfoVin = errocode + ': ' + erromsg
},
complete: function () {
prompt.showToast({
message: "请求完成"
})
}
}) 描述
获取发动机号,需弹框获取用户授权。
OBJECT参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| success | function | 否 | 成功回调。 |
| fail | function | 否 | 失败回调。 |
| complete | function | 否 | 执行结束后的回调。 |
success返回值:
| 参数 | 类型 | 说明 |
|---|---|---|
| engineNo | string | 发动机号。 |
fail返回值:
| 错误码 | 说明 |
|---|---|
| 201 | 用户拒绝授权。 |
| 205 | 该车机不支持。 |
示例代码
device.getCarEngineNo({
success: function (ret) {
that.EngineNo = JSON.stringify(ret);
},
fail: function (erromsg, errocode) {
that.EngineNo = errocode + ': ' + erromsg
},
complete: function () {
prompt.showToast({
message: "请求完成"
})
}
}) 描述
获取车牌颜色。
OBJECT参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| success | function | 否 | 成功回调。 |
| fail | function | 否 | 失败回调。 |
| complete | function | 否 | 执行结束后的回调。 |
success返回值:
| 参数 | 类型 | 说明 |
|---|---|---|
| carNoColor | number | 车牌颜色。 |
fail返回值:
| 错误码 | 说明 |
|---|---|
| 205 | 该车机不支持。 |
示例代码
device.getCarNoColor({
success: function (ret) {
that.CarNoColor = JSON.stringify(ret);
},
fail: function (erromsg, errocode) {
that.CarNoColor = errocode + ': ' + erromsg
},
complete: function () {
prompt.showToast({
message: "请求完成"
})
}
}) 描述
获取车辆注册日期。
OBJECT参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| success | function | 否 | 成功回调。 |
| fail | function | 否 | 失败回调。 |
| complete | function | 否 | 执行结束后的回调。 |
success返回值:
| 参数 | 类型 | 说明 |
|---|---|---|
| registerTime | number | 车辆注册日期。 |
fail返回值:
| 错误码 | 说明 |
|---|---|
| 205 | 该车机不支持。 |
示例代码
device.getCarRegisterTime({
success: function (ret) {
that.RegisterTime = JSON.stringify(ret);
},
fail: function (erromsg, errocode) {
that.RegisterTime = errocode + ': ' + erromsg
},
complete: function () {
prompt.showToast({
message: "请求完成"
})
}
}) 描述
获取车辆座位数。
OBJECT参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| success | function | 否 | 成功回调。 |
| fail | function | 否 | 失败回调。 |
| complete | function | 否 | 执行结束后的回调。 |
success返回值:
| 参数 | 类型 | 说明 |
|---|---|---|
| seatsCount | string | 车牌座位数。 |
fail返回值:
| 错误码 | 说明 |
|---|---|
| 205 | 该车机不支持。 |
示例代码
device.getCarSeatsCount({
success: function (ret) {
that.SeatsCount = JSON.stringify(ret);
},
fail: function (erromsg, errocode) {
that.SeatsCount = errocode + ': ' + erromsg
},
complete: function () {
prompt.showToast({
message: "请求完成"
})
}
}) 描述
获取车辆型号。
OBJECT参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| success | function | 否 | 成功回调。 |
| fail | function | 否 | 失败回调。 |
| complete | function | 否 | 执行结束后的回调。 |
success返回值:
| 参数 | 类型 | 说明 |
|---|---|---|
| infoModel | string | 车辆型号。 |
示例代码
device.getCarInfoModel({
success: function (ret) {
that.InfoModel = JSON.stringify(ret);
},
fail: function (erromsg, errocode) {
that.InfoModel = errocode + ': ' + erromsg
},
complete: function () {
prompt.showToast({
message: "请求完成"
})
}
}) 描述
获取车型年份。
OBJECT参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| success | function | 否 | 成功回调。 |
| fail | function | 否 | 失败回调。 |
| complete | function | 否 | 执行结束后的回调。 |
success返回值:
| 参数 | 类型 | 说明 |
|---|---|---|
| infoModelYear | string | 车型的年份。 |
示例代码
device.getCarInfoModelYear({
success: function (ret) {
that.InfoModelYear = JSON.stringify(ret);
},
fail: function (erromsg, errocode) {
that.InfoModelYear = errocode + ': ' + erromsg
},
complete: function () {
prompt.showToast({
message: "请求完成"
})
}
}) 描述
获取车辆制造商。
OBJECT参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| success | function | 否 | 成功回调。 |
| fail | function | 否 | 失败回调。 |
| complete | function | 否 | 执行结束后的回调。 |
success返回值:
| 参数 | 类型 | 说明 |
|---|---|---|
| manufacturer | string | 车辆制造商。 |
示例代码
device.getCarManufacturer({
success: function (ret) {
that.Manufacturer = JSON.stringify(ret);
},
fail: function (erromsg, errocode) {
that.Manufacturer = errocode + ': ' + erromsg
},
complete: function () {
prompt.showToast({
message: "请求完成"
})
}
}) 描述
检测设备是否为可折叠设备。
返回值
| 返回值 | 说明 |
|---|---|
| true | 该设备是可折叠设备。 |
| false | 该设备不是可折叠设备。 |
示例代码
const isFoldable = device.isFoldable();
console.log('isFoldable ', isFoldable); 描述
检查设备是否支持指定参数的编解码器。
OBJECT参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| codecName | string | Mandatory | 参数取值:h264、h265、h266 。 |
success返回值:
| 参数 | 类型 | 说明 |
|---|---|---|
| - | boolean | 返回一个布尔值,表示设备是否支持指定参数的编解码器。 true:支持 false:不支持 |
示例代码
console.log(device.isCodecSupported('h264')) <template>
<div class="container">
<div class="item-container">
<div class="item-content">
<text>pageGetInfo:</text>
<text>{{pageInfo}}</text>
</div>
<input type="button" class="btn" onclick="getPageInfo" value="getInfoByPage" />
</div>
<div class="item-container">
<div class="item-content">
<text>anti-screenshot:</text>
<text>anti-screenshotStatus:{{isSecure}}</text>
</div>
<input type="button" class="btn" onclick="changeSecure" value="setSecure" />
</div>
<div class="item-container">
<div class="item-content">
<text>deviceInfo:</text>
<text>{{deviceInfo}}</text>
</div>
<input type="button" class="btn" onclick="getDeviceInfo" value="getDeviceInfo" />
</div>
<div class="item-container">
<div class="item-content">
<text>deviceInfoSync:</text>
<text>{{deviceInfoSync}}</text>
</div>
<input type="button" class="btn" onclick="getDeviceInfoSync" value="getDeviceInfoSync" />
</div>
<div class="item-container">
<div class="item-content">
<text>device.id:</text>
<text>{{id}}</text>
</div>
<input type="button" class="btn" onclick="getId" value="getId" />
</div>
<div class="item-container">
<div class="item-content">
<text>deviceId:</text>
<text>{{deviceId}}</text>
</div>
<input type="button" class="btn" onclick="getDeviceId" value="getDeviceId" />
</div>
<div class="item-container">
<div class="item-content">
<text>deviceOAID:</text>
<text>{{OAID}}</text>
</div>
<input type="button" class="btn" onclick="getOAID" value="getDeviceOAID" />
</div>
<div class="item-container">
<div class="item-content">
<text>CountryCode:</text>
<text>{{CountryCode}}</text>
</div>
<input type="button" class="btn" onclick="getCountryCode" value="getCountryCode" />
</div>
<div class="item-container">
<div class="item-content">
<text>serviceCountryCode:</text>
<text>{{serviceCountryCode}}</text>
</div>
<input type="button" class="btn" onclick="getServiceCountryCode" value="getServiceCountryCode" />
</div>
<div class="item-container">
<div class="item-content">
<text>deviceUserId:</text>
<text>{{userId}}</text>
</div>
<input type="button" class="btn" onclick="getUserId" value="getUserId" />
</div>
<div class="item-container">
<div class="item-content">
<text>totalStorage:</text>
<text>{{totalStorage}}</text>
</div>
<input type="button" class="btn" onclick="getTotalStorage" value="getTotalStorage" />
</div>
<div class="item-container">
<div class="item-content">
<text>availableStorage:</text>
<text>{{availableStorage}}</text>
</div>
<input type="button" class="btn" onclick="getAvailableStorage" value="getAvailableStorage" />
</div>
<div class="item-container">
<div class="item-content">
<text>cpuInfo:</text>
<text>{{cpuInfo}}</text>
</div>
<input type="button" class="btn" onclick="getCpuInfo" value="getCpuInfo" />
</div>
<div class="item-container">
<div class="item-content">
<text>device.serial:</text>
<text>{{SNinfo}}</text>
</div>
<input type="button" class="btn" onclick="getSerial" value="getSerial" />
</div>
<div class="item-container">
<div class="item-content">
<text>hostinfo:</text>
<text>{{hostInfo}}</text>
</div>
<input type="button" class="btn" onclick="getHost" value="getHostinfo" />
</div>
<div class="item-container">
<div class="item-content">
<text>localedatetime:</text>
<text>{{localeDateTimeString}}</text>
</div>
<input type="button" class="btn" onclick="tolocaleDateTimeString" value="getLocaleDateTime" />
</div>
<div class="item-container">
<div class="item-content">
<text>localedate:</text>
<text>{{localeDateString}}</text>
</div>
<input type="button" class="btn" onclick="tolocaleDateString" value="getLocaleDate" />
</div>
<div class="item-container">
<div class="item-content">
<text>localetime:</text>
<text>{{localeTimeString}}</text>
</div>
<input type="button" class="btn" onclick="tolocaleTimeString" value="getLocaleTime" />
</div>
</div>
</template>
<style>
.container {
flex: 1;
flex-direction: column;
}
.item-container {
margin-bottom: 50px;
margin-right: 60px;
margin-left: 60px;
flex-direction: column;
}
.item-content {
flex-direction: column;
padding: 30px;
margin-bottom: 50px;
align-items: flex-start;
}
.btn {
height: 80px;
text-align: center;
border-radius: 5px;
margin-right: 60px;
margin-left: 60px;
margin-bottom: 50px;
color: #ffffff;
font-size: 30px;
background-color: #0faeff;
}
</style>
<script>
import device from '@system.device'
import prompt from '@system.prompt'
export default {
data: {
deviceInfo: '',
themeInfo: '',
deviceInfoSync: '',
themeInfoSync: '',
id: '',
deviceId: '',
OAID: '',
userId: '',
serviceCountryCode: '',
CountryCode: '',
totalStorage: '',
availableStorage: '',
cpuInfo: '',
SNinfo: '',
pageInfo: '',
hostInfo: '',
isSecure: false,
localeDateTimeString: '',
localeDateString: '',
localeTimeString: ''
},
onInit() {
this.$page.setTitleBar({ text: 'device' })
device.onFontScaleChange({
callback: function (ret) {
console.log('fontScale ==' + ret.fontScale)
prompt.showToast({
message: 'fontScale ==' + ret.fontScale
})
}
})
},
getPageInfo: function () {
this.pageInfo = 'windowHeight = ' + this.$page.windowHeight
+ ' windowWidth = ' + this.$page.windowWidth
+ ' statusBarHeight = ' + this.$page.statusBarHeight
},
changeSecure: function () {
this.isSecure = !this.isSecure
this.$page.setSecure(this.isSecure)
},
getDeviceInfo: function () {
var that = this
device.getInfo({
success: function (ret) {
that.deviceInfo = JSON.stringify(ret)
},
fail: function (erromsg, errocode) {
that.deviceInfo = errocode + ': ' + erromsg
},
complete: function () {
prompt.showToast({
message: "requestSuccess"
})
}
})
},
getDeviceInfoSync: function () {
try {
var info = device.getInfoSync()
this.deviceInfoSync = JSON.stringify(info)
} catch (e) { }
},
getId: function () {
var that = this
device.getId({
type: ['device', 'mac', 'user'],
success: function (ret) {
that.id = JSON.stringify(ret)
},
fail: function (erromsg, errocode) {
that.id = errocode + ': ' + erromsg
},
complete: function () {
prompt.showToast({
message: "request Success"
})
}
})
},
getDeviceId: function () {
var that = this
device.getDeviceId({
success: function (ret) {
that.deviceId = JSON.stringify(ret)
},
fail: function (erromsg, errocode) {
that.deviceId = errocode + ': ' + erromsg
},
complete: function () {
prompt.showToast({
message: "request Success"
})
}
})
},
getServiceCountryCode: function () {
var that = this
device.getServiceCountryCode({
success: function (ret) {
that.serviceCountryCode = ret.serviceCountryCode
},
fail: function (erromsg, errocode) {
that.serviceCountryCode = errocode + ': ' + erromsg
},
complete: function () {
prompt.showToast({
message: 'getServiceCountryCode success'
})
}
})
},
getCountryCode: function () {
var that = this
device.getCountryCode({
success: function (ret) {
that.CountryCode = ret.countryCode
},
fail: function (erromsg, errocode) {
that.CountryCode = errocode + ': ' + erromsg
},
complete: function () {
prompt.showToast({
message: 'getCountryCode success'
})
}
})
},
getOAID: function () {
var that = this
device.getOAID({
success: function (ret) {
that.OAID = JSON.stringify(ret)
},
fail: function (erromsg, errocode) {
that.OAID = errocode + ': ' + erromsg
},
complete: function () {
console.log("message" + device.platform.versionCode);
prompt.showToast({
message: 'getOAID ' + device.allowTrackOAID
})
}
})
},
getUserId: function () {
var that = this
device.getUserId({
success: function (ret) {
that.userId = JSON.stringify(ret)
},
fail: function (erromsg, errocode) {
that.userId = errocode + ': ' + erromsg
},
complete: function () {
prompt.showToast({
message: "request Success"
})
}
})
},
getTotalStorage: function () {
var that = this
device.getTotalStorage({
success: function (ret) {
that.totalStorage = JSON.stringify(ret)
},
fail: function (erromsg, errocode) {
that.totalStorage = errocode + ': ' + erromsg
},
complete: function () {
prompt.showToast({
message: "request Success"
})
}
})
},
getAvailableStorage: function () {
var that = this
device.getAvailableStorage({
success: function (ret) {
that.availableStorage = JSON.stringify(ret)
},
fail: function (erromsg, errocode) {
that.availableStorage = errocode + ': ' + erromsg
},
complete: function () {
prompt.showToast({
message: "requestSuccess"
})
}
})
},
getCpuInfo: function () {
var that = this
device.getCpuInfo({
success: function (ret) {
that.cpuInfo = JSON.stringify(ret)
},
fail: function (erromsg, errocode) {
that.cpuInfo = errocode + ': ' + erromsg
},
complete: function () {
prompt.showToast({
message: "request Success"
})
}
})
},
getSerial: function () {
var that = this
device.getSerial({
success: function (ret) {
that.SNinfo = JSON.stringify(ret)
},
fail: function (erromsg, errocode) {
that.SNinfo = errocode + ': ' + erromsg
},
complete: function () {
prompt.showToast({
message: "request Success"
})
}
})
},
getHost: function () {
var that = this
device.host({
success: function (ret) {
console.log('host succ data:' + JSON.stringify(ret))
that.hostInfo = JSON.stringify(ret)
},
fail: function (erromsg, errocode) {
that.hostInfo = errocode + ': ' + erromsg
},
complete: function () {
prompt.showToast({
message: "requestSuccess"
})
}
})
},
tolocaleDateTimeString: function () {
this.localeDateTimeString = device.toLocaleDateTimeString(12345678910)
},
tolocaleDateString: function () {
this.localeDateString = device.toLocaleDateString(100000000)
},
tolocaleTimeString: function () {
this.localeTimeString = device.toLocaleTimeString(100000000)
}
}
</script> 效果图如下:

| 版本 | 发布日期 | 描述 |
|---|---|---|
| 1110 | 2024-02-07 |
|
| 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 |
|
| 1060 | 2019-12-10 |
|
| 1050 | 2019-09-20 |
|
| 1040 | 2019-06-24 |
|
| 1030 | 2018-10-31 | 新增platform对象,通过该对象的versionCode属性,可以获取平台的版本号。 |
| 1020 | 2018-06-20 | device.getInfo(OBJECT)接口新增 windowWidth、windowHeight、statusBarHeight和pixelRatio 4个返回值。 |