Add the following configuration to the features attribute in the manifest.json file:
{"name": "system.device"} Add the following configuration to the script element on the page where the API will be called:
import device from '@system.device'
Or
var device = require("@system.device") Item | Description |
|---|---|
Applicable devices | Mobile phones, tablets, and telematics devices. Vision products support some APIs. |
Applicable regions | Global |
Attribute | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
platform | object | - | No | Platform information. The object contains the versionCode attribute, indicating the platform version code. |
allowTrackOAID (1060+) | boolean | - | No | Indicates whether OAIDs and device IDs of devices running HarmonyOS 2.0, Android 10.0, or any later version can be used for ad tracking. The value true indicates that they can be used for ad tracing. If the parameter is updated, Huawei Quick App Engine process needs to be restarted for the update to take effect. Otherwise, the cached value still takes effect. |
API | Description |
|---|---|
Obtains device information. | |
Obtains device information. | |
Obtains the device ID. | |
Obtains the unique ID of a device under authorization of the device user. | |
Obtains the unique ID of the device user. | |
Obtains the OAID of a device. You are advised to use this API only for ads scenarios. | |
Obtains the total internal storage space, excluding the storage space provided by an external SD card. | |
Obtains the serial number of a device under authorization of the device user. | |
Obtains available internal storage space, excluding the available storage space provided by an external SD card. | |
Obtains CPU information. | |
Listens to changes on the system font settings. When the system font settings change, the callback function is triggered. For a card, when the host app detects any change, it notifies the Fastview SDK of the change through onConfigurationChanged(Configuration newConfig). Then the Fastview SDK triggers the callback function for the onFontScaleChange event. | |
Obtains the current service country/region code of Huawei Quick App Center. If the service country/region is outside the Chinese mainland, some capabilities such as WeChat sharing, WeChat Pay, Alipay, and Weibo sharing are unavailable. The return value of this API may be different from the code of the country/region set on the operating system. | |
Obtains the code of the country/region where the current signed-in HUAWEI ID of Huawei Quick App Center is registered. | |
Converts a timestamp to a string in the same format as the system date and time. | |
Converts a timestamp to a string in the same format as the system date. | |
Converts a timestamp to a string in the same format as the system time. | |
Obtains the package name, version code, and version name of the host app. | |
Checks whether the device is foldable. |
Description
Obtains device information.
OBJECT
Parameter | Type | Mandatory | Description |
|---|---|---|---|
success | function | No | Callback upon success. |
fail | function | No | Callback upon failure. |
complete | function | No | Callback upon completion. |
Parameters returned by success
Parameter | Type | Description |
|---|---|---|
brand | string | Device brand. |
manufacturer | string | Device manufacturer. |
model | string | Device model. |
product | string | Device code. |
osType | string | Operating system name. |
osVersionName | string | Operating system version name. |
osVersionCode | number | Operating system version code. |
platformVersionName | string | Platform version name. |
platformVersionCode | number | Platform version code. |
language | string | System language. |
region | string | System country/region. |
screenWidth | number | Screen width. |
screenHeight | number | Screen height. |
engineProvider | string | Engine provider. This is a Huawei extended parameter, but not a standard parameter defined by the vendor alliance. The fixed value huawei is returned. |
windowWidth (1020+) | number | Available window width, which is determined by the actual screen resolution. |
windowHeight (1020+) | number | Available window height, which is determined by the actual screen resolution. Available window height = Screen height - Status bar height - Title bar height - Virtual navigation bar height |
cutout (1080+) | array | Returns the position of irregular area of a curved screen such as a notched screen, drop screen or screen with cutout. Parameters are:
Example: cutout: [{"left":0,"top":0,"right":955,"bottom":2208}]. |
statusBarHeight (1020+) | number | Status bar height, which is determined by the actual screen resolution. |
pixelRatio (1020+) | number | Device pixel ratio (defined by Huawei rather than the vendor alliance). |
screenDensity (1035+) | number | Screen density of the device. |
screenLogicWidth | number | Screen logic width of the device. |
screenLogicHeight | number | Screen logic height of the device. |
timeZone (1040+) | string | Current system time zone. |
emuiVer (1040+) | string | EMUI version number, for example, 9.0.0. |
fontScale (1040+) | number | Font size, which can be set by setting Text size under System > Settings > General, for example, 0.9, 1, 1.1, 1.2, or 1.5. |
characteristics (1040+) | string | Device type, which is obtained from ro.build.characteristics. The options are default, tv, tablet, and phone. The default value is phone. |
windowLogicWidth (1040+) | number |
|
windowLogicHeight (1040+) | number | For a card, the base value is 750. The host app assigns the actual height to the card. This parameter is exclusive to cards. If no specific height is assigned to the card by the host app, this value cannot be obtained. |
emuiApiLevel (1050+) | string | API level of the operating system, for example, 18. |
marketingName (1060+) | string | Model marketing name, for example, P20 Pro. |
harmonyOSVer (1078+) | string | Version number of HarmonyOS, for example, 2.0.0. |
vendorOsName (1080+) | string | OS name. |
vendorOsVersion (1080+) | string | OS version number. |
deviceType (1090+) | string | Device type. The options are as follows:
|
Sample code
device.getInfo({
success: function (ret) {
console.log("handling success:",JSON.stringify(ret));
},
fail: function (erromsg, errocode) {
console.log("message:",erromsg,errocode);
}
}) The output is as follows:
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": "" } Description
Obtains device information.
Returns
Parameter | Type | Description |
|---|---|---|
brand | string | Device brand. |
manufacturer | string | Device manufacturer. |
model | string | Device model. |
product | string | Device code. |
osType | string | Operating system name. |
osVersionName | string | Operating system version name. |
osVersionCode | number | Operating system version code. |
platformVersionName | string | Platform version name. |
platformVersionCode | number | Platform version code. |
language | string | System language. |
region | string | System country/region. |
screenWidth | number | Screen width. |
screenHeight | number | Screen height. |
engineProvider | string | Engine provider. This is a Huawei extended parameter, but not a standard parameter defined by the vendor alliance. The fixed value huawei is returned. |
windowWidth (1020+) | number | Available window width, which is determined by the actual screen resolution. |
windowHeight (1020+) | number | Available window height, which is determined by the actual screen resolution. Available window height = Screen height - Status bar height - Title bar height - Virtual navigation bar height |
statusBarHeight (1020+) | number | Status bar height, which is determined by the actual screen resolution. |
pixelRatio (1020+) | number | Device pixel ratio (defined by Huawei rather than the vendor alliance). |
screenDensity (1035+) | number | Screen density of the device. |
timeZone (1040+) | string | Current system time zone. |
emuiVer (1040+) | string | EMUI version number, for example, 9.0.0. |
fontScale (1040+) | number | Font size, which can be set by setting Text size under System > Settings > General > Text size, for example, 0.9, 1, 1.1, 1.2, or 1.5. |
characteristics (1040+) | string | Device type, which is obtained from ro.build.characteristics. The options are default, tv, tablet, and phone. The default value is phone. |
windowLogicWidth (1040+) | number |
|
windowLogicHeight (1040+) | number | For a card, the base value is 750. The host app assigns the actual height to the card. This parameter is exclusive to cards. If no specific height is assigned to the card by the host app, this value cannot be obtained. |
emuiApiLevel (1050+) | string | API level of the operating system, for example, 18. |
marketingName (1060+) | string | Model marketing name, for example, P20 Pro. |
harmonyOSVer (1078+) | string | Version number of HarmonyOS, for example, 2.0.0. |
Sample code
try {
const res = device.getInfoSync();
console.log(res. brand);
console.log(res. model);
} catch (e) {
// Do something upon an error.
console.log(e.code + e.message);
} Description
Obtains the device ID, user ID, and MAC address.
This API does not support Vision products and cards.
In versions earlier than Android 10.0, a pop-up message is displayed for authorization. In HarmonyOS 2.0, Android 10.0, and their later versions, such pop-up message is not displayed.
OBJECT
Parameter | Type | Mandatory | Description |
|---|---|---|---|
type | array | Yes | Type of the ID to be obtained. The options are device, mac, and user. One or more options can be submitted. |
success | function | No | Callback upon success. Parameter format: {"device":"1234567890","mac":"abcdef123456","user":"abcdef123456"}. For each ID type option, an ID is returned only when the specific option is passed. When the Quick App Engine version is 3.2.1.310 or later, or the version is earlier than 3.2.1.310 and the Android version is 6.0 and later, the fixed value 02:00:00:00:00:00 is returned for the mac option. |
fail | function | No | Callback upon failure. |
complete | function | No | Callback upon completion. |
Parameters returned by success
Parameter | Type | Description |
|---|---|---|
device | string | Unique device ID. In versions earlier than Android 10.0, the IMEI or MEID is returned. In HarmonyOS 2.0, Android 10.0, and their later versions, the AAID is returned, which is unique to each quick app. The AAID changes after app data is cleared or the app is uninstalled. |
mac | string | MAC address of a device. In versions earlier than Android 6.0, the MAC address of the device is returned. In HarmonyOS 2.0, Android 6.0, and their later versions, a fixed value is returned. |
user | string | Unique user ID. In versions earlier than Android 10.0, the value of ANDROID_ID is returned. In HarmonyOS 2.0, Android 10.0, and their later versions, the value varies depending on the signing certificate fingerprint of the quick app. The obtained value changes in the following scenarios:
|
Result codes returned by fail
Result Code | Description |
|---|---|
201 | Failed to obtain the call permission. The user rejects authorization. |
Sample code
device.getId({
type: ["device", "mac"],
success:function(data) {
console.log("handling success: " + data.device);
},
fail: function(data, code) {
console.log("handling fail, code=" + code);
}
}) Description
Obtains the identifier of a device.
This API does not support Vision products and cards.
In versions earlier than Android 10.0, a pop-up message is displayed for authorization. In HarmonyOS 2.0, Android 10.0, and their later versions, such pop-up message is not displayed.
OBJECT
Parameter | Type | Mandatory | Description |
|---|---|---|---|
success | function | No | Callback upon success. |
fail | function | No | Callback upon failure. |
complete | function | No | Callback upon completion. |
Parameters returned by success
Parameter | Type | Description |
|---|---|---|
deviceId | string | Unique device ID. In versions earlier than Android 10.0, the IMEI or MEID is returned. In HarmonyOS 2.0, Android 10.0, and their later versions, the AAID is returned, which is unique to each quick app. The AAID changes after app data is cleared or the app is uninstalled. |
Result codes returned by fail
Result Code | Description |
|---|---|
201 | The user rejects authorization. |
Sample code
device.getDeviceId({
success: function(data) {
console.log("handling success: " + data.deviceId);
},
fail: function(data, code) {
console.log("handling fail, code=" + code);
}
}) Description
Obtains a user ID.
This API does not support Vision products and cards.
No pop-up will be displayed for authorization.
OBJECT
Parameter | Type | Mandatory | Description |
|---|---|---|---|
success | function | No | Callback upon success. |
fail | function | No | Callback upon failure. |
complete | function | No | Callback upon completion. |
Parameters returned by success
Parameter | Type | Description |
|---|---|---|
userId | string | Unique user ID. In versions earlier than Android 10.0, the value of ANDROID_ID is returned. In HarmonyOS 2.0, Android 10.0, and their later versions, the value varies depending on the signing certificate fingerprint of the quick app. For HarmonyOS 2.0, Android 10.0, and their later versions, the value contains 64 characters. The obtained value changes in the following scenarios:
|
Sample code
device.getUserId({
success: function(data) {
console.log("handling success: " + data.userId);
},
fail: function(data, code) {
console.log("handling fail, code=" + code);
}
}) Description
Obtains the OAID of a device. You are advised to use this API only for ads scenarios.
Vision products, telematics devices, and cards do not support this API.
OBJECT
Parameter | Type | Mandatory | Description |
|---|---|---|---|
success | function | No | Callback upon success. |
fail | function | No | Callback upon failure. |
complete | unction | No | Callback upon completion. |
Parameters returned by success
Parameter | Type | Description |
|---|---|---|
oaid | string | OAID of the device. If the current device does not support OAID, a null value is returned. The value changes after a user resets the OAID. After the setting of Disable personalized ads is enabled on the device, the return value is a character string consisting of zeros. |
Sample code
device.getOAID({
success: function (ret) {
that.OAID = JSON.stringify(ret);
},
fail: function (erromsg, errocode) {
that.OAID = errocode + ': ' + erromsg
},
complete: function () {
prompt.showToast({
message: "The request is completed." + device.allowTrackOAID
})
}
}) Description
Obtains the total internal storage space, excluding the storage space provided by an external SD card.
OBJECT
Parameter | Type | Mandatory | Description |
|---|---|---|---|
success | function | No | Callback upon success. |
fail | function | No | Callback upon failure. |
complete | function | No | Callback upon completion. |
Parameters returned by success
Parameter | Type | Description |
|---|---|---|
totalStorage | long | Total storage space, in bytes. For an Android device, the total external storage space is returned. |
Sample code
device.getTotalStorage({
success:function(data) {
console.log("handling success: " + data.totalStorage);
},
fail: function(data, code) {
console.log("handling fail, code=" + code);
}
}) Description
Obtains the serial number of a device under authorization of the device user.
This API does not support Vision products and cards.
In HarmonyOS 2.0, Android 10.0, and their later versions, the return value cannot be obtained and the fail callback will be executed.
OBJECT
Parameter | Type | Mandatory | Description |
|---|---|---|---|
success | function | No | Callback upon success. |
fail | function | No | Callback upon failure. |
complete | function | No | Callback upon completion. |
Parameters returned by success
Parameter | Type | Description |
|---|---|---|
serial | string | Serial number of the device. |
Parameters returned by fail
Result Code | Description |
|---|---|
201 | The user rejects authorization. |
Sample code
device.getSerial({
success: function (ret) {
console.log("handling success: " +JSON.stringify(ret));
},
fail: function (erromsg, errocode) {
console.log("handling success: "+ errocode + ': ' + erromsg)
},
complete: function () {
prompt.showToast({
message: "The request is completed."
})
}
}) Description
Obtains available internal storage space, excluding the available storage space provided by an external SD card.
OBJECT
Parameter | Type | Mandatory | Description |
|---|---|---|---|
success | function | No | Callback upon success. |
fail | function | No | Callback upon failure. |
complete | function | No | Callback upon completion. |
Parameters returned by success
Parameter | Type | Description |
|---|---|---|
availableStorage | long | Available storage space, in bytes. For an Android device, the size of available external storage space is returned. |
Sample code
device.getAvailableStorage({
success:function(data) {
console.log("handling success: " + data.availableStorage);
},
fail: function(data, code) {
console.log("handling fail, code=" + code);
}
}) Description
Obtains CPU information.
OBJECT
Parameter | Type | Mandatory | Description |
|---|---|---|---|
success | function | No | Callback upon success. |
fail | function | No | Callback upon failure. |
complete | function | No | Callback upon completion. |
Parameters returned by success
Parameter | Type | Description |
|---|---|---|
cpuInfo | string | CPU information. For an Android device, content in the /proc/cpuinfo file is returned. |
Sample code
device.getCpuInfo({
success:function(data) {
console.log("handling success: " + data.cpuInfo);
},
fail: function(data, code) {
console.log("handling fail, code=" + code);
}
}) Description
Listens to changes on the system font settings. When the system font settings change, the callback function is triggered. For a card, when the host app detects any change, it notifies the Fastview SDK of the change through onConfigurationChanged(Configuration newConfig). Then the Fastview SDK triggers the callback function for the onFontScaleChange event.
OBJECT
Parameter | Type | Mandatory | Description |
|---|---|---|---|
callback | function | No | This function is called back whenever the system font setting changes. |
Returns
Parameter | Type | Description |
|---|---|---|
fontScale | number | Font size, which can be set by setting Text size under System > Settings > General, for example, 0.9, 1, 1.1, 1.2, or 1.5. |
Sample code
device.onFontScaleChange({
callback: function(ret) {
console.log("fontScale ==" + ret.fontScale);
}
}) Description
Obtains the current service country/region code of Huawei Quick App Center. If the service country/region is outside the Chinese mainland, some capabilities such as WeChat sharing, WeChat Pay, Alipay, and Weibo sharing are unavailable. The return value of this API may be different from the code of the country/region set on the operating system.
OBJECT
Parameter | Type | Mandatory | Description |
|---|---|---|---|
success | function | No | Callback upon success. |
fail | function | No | Callback upon failure. |
complete | function | No | Callback upon completion. |
Parameters returned by success
Parameter | Type | Description |
|---|---|---|
serviceCountryCode | string | Current service country/region code of Huawei Quick App Center, which complies with the ISO 3166 standard, for example, CN (China) and JP (Japan). |
Result codes returned by fail
Result Code | Description |
|---|---|
200 | General error. |
Sample code
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: "The request is completed."
})
}
}) Description
Obtains the code of the country/region where the current signed-in HUAWEI ID of Huawei Quick App Center is registered.
When Huawei Quick App Loader is used for debugging, the information cannot be obtained.
OBJECT
Parameter | Type | Mandatory | Description |
|---|---|---|---|
success | function | No | Callback upon success. |
fail | function | No | Callback upon failure. |
complete | function | No | Callback upon completion. |
Parameters returned by success
Parameter | Type | Description |
|---|---|---|
countryCode | string | Current service country/region code of Huawei Quick App Center, which complies with the ISO 3166 standard, for example, CN (China) and JP (Japan). |
Result codes returned by fail
Result Code | Description |
|---|---|
200 | General error. |
Sample code
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: "The request is completed."
})
}
}) Description
Converts a timestamp to a string in the same format as the system date and time.
This method uses the synchronous mode.
Parameters
Parameter | Type | Mandatory | Description |
|---|---|---|---|
timeStamp | number | Yes | Standard timestamp. |
Returns
Parameter | Type | Description |
|---|---|---|
- | string | A string that is in the same format as the system date and time and contains information about the date and time. |
Sample code
console.log(device.toLocaleDateTimeString(123456))
Description
Converts a timestamp to a string in the same format as the system date.
This method uses the synchronous mode.
Parameters
Parameter | Type | Mandatory | Description |
|---|---|---|---|
timeStamp | number | Yes | Standard timestamp. |
Returns
Parameter | Type | Description |
|---|---|---|
- | string | A string that is in the same format as the system date and time and contains information about the date and time. |
Sample code
console.log(device.toLocaleDateString(123456))
Description
Converts a timestamp to a string in the same format as the system date.
This method uses the synchronous mode.
Parameters
Parameter | Type | Mandatory | Description |
|---|---|---|---|
timeStamp | number | Yes | Standard timestamp. |
Returns
Parameter | Type | Description |
|---|---|---|
- | string | A string that is in the same format as the system date and time and contains information about the date and time. |
Sample code
console.log(device.toLocaleTimeString(123456))
Description
Obtains the package name, version code, and version name of the host app. For a quick app, information about Huawei Quick App Loader or Huawei Quick App Center is returned. For a card, the APK information about the host app is returned.
OBJECT
Parameter | Type | Mandatory | Description |
|---|---|---|---|
success | function | No | Callback upon success. |
fail | function | No | Callback upon failure. |
complete | function | No | Callback upon completion. |
Parameters returned by success
Parameter | Type | Description |
|---|---|---|
package | string | Package name of the host app. |
versionCode | number | Version code of the host app. |
versionName | string | Version name of the host app. |
Parameters returned by fail
Result Code | Description |
|---|---|
203 | Service unavailable. |
Sample code
device.host({
success: function (ret) {
console.log("handling success: " + JSON.stringify(ret));
},
fail: function (erromsg, errocode) {
console.log("handling success: " + errocode + ': ' + erromsg)
},
}) Description
Checks whether the device is foldable.
Returns
Return Value | Description |
|---|---|
true | The device is foldable. |
false | The device is not foldable. |
Sample code
const isFoldable = device.isFoldable();
console.log('isFoldable ', isFoldable); <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> The following figure shows the final effect.

Version | Date | Description |
|---|---|---|
1090 | 2022-05-19 | Added the deviceType parameters for the device.getInfo(OBJECT) API. |
1083 | 2022-03-21 | Added the isFoldable method to check whether the device is foldable. |
1080 | 2021-12-28 | Added the vendorOsName and vendorOsVersion parameters in the device.getInfo(OBJECT) API. |
1070 | 2020-05-19 |
|
1060 | 2019-12-10 |
|
1050 | 2019-09-20 |
|
1040 | 2019-06-24 |
|
1030 | 2018-10-31 | Added the platform object, in which the versionCode attribute can be used to obtain the platform version number. |
1020 | 2018-06-20 | Added the return parameters windowWidth, windowHeight, statusBarHeight, and pixelRatio to the device.getInfo(OBJECT) API. |