Read the original article:How do I determine whether the watch device is round or rectangle?
Question
In some development scenarios, you need to know the screen shape of the device. How do you determine whether the watch is round or rectangle? What APIs are used?
Short Answer
Different APIs need to be used in the JS and arkts projects to obtain the wearable watch shape.
1、JS project, which is obtained using @system.device. For details about APIs, see:screenShape
1.Importing Modules
import device from '@system.device';
2.Use device.getInfo to obtain data. data.screenShape is the screen shape. ScreenShape Enumerated values: rect: rectangle; circle: round
device.getInfo({
success: (data) => {
console.log('Device information obtained successfully. Device brand:' + data.brand+'screenShape='+data.screenShape);
},
fail: function(data, code) {
console.log('Failed to obtain device information. Error code:'+ code + '; Error information: ' + data);
this.message = 'Failed to obtain device information.'
},
});
2、Arkts project, which is obtained by using display of @kit.ArkUI. For details about APIs, see:display
1.Importing Modules
import { display } from '@kit.ArkUI';
2.Use display.getAllDisplays to obtain data, where screenShape in data is the screen shape. ScreenShape Enumerated value: 1: round; 0: rectangle
let displayClass: Array<display.Display> = [];
display.getAllDisplays((err: BusinessError, data: Array<display.Display>) => {
displayClass = data;
const errCode: number = err.code;
if (errCode) {
console.error(`Failed to obtain all the display888 objects. Code: ${err.code}, message: ${err.message}`);
return;
}
console.info('Succeeded in obtaining all the display888 objects. Data: ' + JSON.stringify(data));
});
Applicable Scenarios
- When determining whether a wearable device has a round or rectangular screen.
- When selecting the correct API (JS or ArkTS) to obtain the watch shape in development.

Top comments (0)