Huawei provides various services for developers to make ease of development and provides best user experience to end users. In this article, we will cover Camera device with Java in Harmony OS.
The HarmonyOS camera module enables your application to provide camera functions. You can access and operate the camera device and develop new functions through the open APIs. Common operations include preview, photographing, burst photographing, and video recording.
- Static camera capability
A series of parameters used to describe inherent capabilities of a camera, such as orientation and supported resolution
- Physical camera
A physical camera is an independent camera device. The physical camera ID is a string that uniquely identifies a physical camera.
- Logical camera
A logical camera is the abstracted capability of many physical cameras and centrally controls these physical cameras to implement camera functions, such as wide aperture and zooming. A logical camera ID is a unique character string that identifies the abstraction capability of multiple physical cameras.
- Frame capture
All actions of capturing frames after a camera is started, including single-frame capture, multi-frame capture and looping-frame capture.
- Single-frame capture
This function captures one frame in the frame data stream transmitted after the camera is started. It is frequently used for photographing.
- Multi-frame capture
This function repeatedly captures multiple frames in the frame data stream transmitted after the camera is started. It is frequently used for burst photographing.
You need to install DevEcho studio IDE and I assume that you have prior knowledge about the Harmony OS and java.
- A computer (desktop or laptop) running Windows 10.
- A Huawei phone (with the USB cable), which is used for debugging.
- Java JDK installation package.
- DevEcho studio installed.
Follows the steps.
- Create Harmony OS Project.
- Open DevEcho studio.
- Click NEW Project, select a Project Templet.
- Select Empty Ability(Java) template and click Next as per below image.
- Enter Project Name and Package Name and click on Finish.
2. Once you have created the project, DevEco Studio will automatically sync it with Gradle files. Find the below image after synchronization is successful.
3. Add the below maven URL in build.gradle(Project level) file under the repositories of buildscript, dependencies, for more information refer Add Configuration.
4. Update Permission and app version in config.json file as per your requirement, otherwise retain the default values.
5. Create New > Ability, as follows.
6. Development Procedure.
Create MainAbility.java ability and add the below code.
Create TakePhotoAbility.java ability and add the below code.
Create VideoRecordAbility.java ability and add the below code.
Create ability_main.xml layout and add the below code.
Create main_camera_slice.xml in graphic folder and add the below code
7. To build apk and run in device, choose Build > Generate Key and CSR Build for Hap(s)\ APP(s) or Build and Run into connected device, follow the steps.
- Run Application on connected device, we can see below result.
2. Click on button, one by one see result as per below screen.
Tips and Tricks
- Always use the latest version of DevEcho Studio.
- Use Harmony Device Simulator from HVD section.
- Do not forgot to add permission in config.json file.
- To ensure better compatibility of your application, you must query the supported camera capabilities before creating a camera instance or setting related parameters.
In this article, we have learnt Camera service in Harmony OS. We can access and operate the camera device and develop new functions through the open APIs. Common operations include preview, photographing, burst photographing, and video recording.
Thanks for reading the article, please do like and comment your queries or suggestions.