DEV Community

Cover image for HarmonyOS Development: Screen Caption and Screen Recording Functions in DevEco Studio
程序员一鸣
程序员一鸣

Posted on

HarmonyOS Development: Screen Caption and Screen Recording Functions in DevEco Studio

Foreword

this article API>= 13, based on DevEco Studio 5.1.0 Release, version number 5.1.0.828

when debugging an application on a real machine, if you want to intercept a page in the device or record a video, and then use or view it on the computer, how do you do it? Presumably, many people will think of the first time, using the screen capture or recording screen function that comes with the real machine, and then sending it to the computer after Operation. Is there any other way besides this traditional way?

I don't know, do you still remember the article that outlined the DevEcoTesting tool before, which mentioned a function, the screen projection function. We use the screen projection function to projection the device onto the computer. Whether it is a screen capture or a screen recording, it is very convenient. The disadvantage is that the screen projection function needs to download the screen projection tool.

In addition to the above two methods, in fact, DevEco Studio has integrated screen capture and screen recording functions. We can use our own functions to help us realize it. Compared with other methods, it is simpler and more convenient.

Whether it is a screenshot or a recording screen, we need to pay attention to the fact that the equipment must be connected, which can be a simulator or a real machine.

Screenshot function

tools Screenshot

open the log log console at the bottom. There is a camera icon on the left. This is the screenshot function.

Image description

After clicking the screenshot, it will pop up the path of the picture to save. You can choose any path to save. Please remember the location to save so as to facilitate future viewing and operation.

Image description

After confirmation, it will be automatically displayed in DevEco Studio.

Image description

Command mode screenshot

mainly using the hdc command, it can be used to debug the command-line tool, through the tool can achieve screenshot function.

Method 1: hdc shell snapshot_display

hdc shell snapshot_display -f /data/local/tmp/0.jpeg  // -The f parameter specifies the storage path of the image on the device. If not specified, the default storage path of the image will be displayed after the command is executed.
hdc file recv /data/local/tmp/0.jpeg  // Send the image from the device to the local directory. In this example, send the image to the directory where the current HDC command is being executed
Enter fullscreen mode Exit fullscreen mode

method 2: hdc shell wukong special -p

wukong is a system stability testing tool, which can realize the screenshot function by specifying the parameter-p.

hdc shell wukong special -p
Enter fullscreen mode Exit fullscreen mode

Screen recording function

compared with the screen capture, the recording screen has certain constraints. At present, only the real machine recording screen is supported, and the simulator is not supported. Also, before recording the screen, it is necessary to ensure that the real machine unlocks the device screen, because the recording screen application cannot be pulled up normally in the locked screen state. Another point is that if the screen is locked during the recording process, the recording screen application will exit.

Tool recording screen

open the log log console at the bottom. There is a video recorder icon on the left. This is the screen recording function.

Image description

After clicking, just like the screenshot function, you need to select the location to save.

Image description

After the location is selected, you will enter the option to open the Recording screen, as shown below, click Start Recording to enter the Recording screen link.

Image description

After entering the Recording screen link, you can find that your real machine has also turned on the Recording screen, which calls the Recording screen function of your real machine. You can click Stop Recording to Stop the Recording screen.

Image description

After stopping the recording screen, the following window will pop up, you can choose to view:

Image description

command mode recording screen

Like screenshots, hdc is still used, which can be used as a command-line tool for debugging, through which the screen recording function can be realized.

Start the recording screen.

hdc shell aa start -b com.huawei.hmos.screenrecorder -a com.huawei.hmos.screenrecorder.ServiceExtAbility --ps "CustomizedFileName" "test.mp4" 
Enter fullscreen mode Exit fullscreen mode

Stop recording screen.

hdc shell aa start -b com.huawei.hmos.screenrecorder -a com.huawei.hmos.screenrecorder.ServiceExtAbility
Enter fullscreen mode Exit fullscreen mode

Obtain the location of the screen recording file. The record is {RecordFile}.

hdc shell mediatool query test.mp4 -u
Enter fullscreen mode Exit fullscreen mode

Related Summary

there are two ways to implement screen capture and screen recording. It is recommended to use the first one, which is simple and convenient. In actual development, if it is necessary to show others various functions of the application under development, we can assist screen capture and screen recording functions to realize.

Top comments (0)