Development Tips

Camera Access Control

Accessing cameras should be managed carefully, since camera hardware is a shared resource that multiple applications can request access to the same camera.

Check for Camera Availability

Make sure that cameras are accessible at runtime by checking their existence. Check whether the smartphone supports the camera feature by using the PackageManager.hasSystemFeature() method. PackageManager instance can be obtained by using the Context.getPackagerManager() method. Check the availability of the camera service by using the Context.getSystemService() method.

Both PackageManager and SystemService are closely linked with the Context from which they are obtained. It is a good design practice not to switch between different Contexts to manage PackageManager and SystemService.

Check Whether Camera is in Use

Make sure to open the camera first to check whether it is already opened by any other application. When opening a camera with Camera.open() or CameraManager.openCamera(), these methods throw exceptions that indicate whether the camera is already in use by other application or other errors has occurred.

 

Also, be considerate of the activity’s lifecycle. Opening a camera from the onCreate() method just once is not a good idea. Cameras need to be re-opened if the user has left the activity and comes back again. Suppose a camera was successfully opened at the startup of your activity from the onCreate() method. If your activity gets paused or stopped, other application running the top foreground activity gets a higher priority to the camera and therefore can open the camera from there. If the user restarts your activity, the camera is being in use by other application (not the application running your activity). Therefore the camera should be re-opened when the activity gets resumed (from the onResume() method), otherwise any subsequent call to the camera device might throw exception errors.

Release Camera for Other Applications

The camera that has been opened from an application should be properly released (or closed) once the application is done using the camera. If the camera is not released, then the camera might not be opened even within the same application. Call the release() method on the Camera instance or call the close() method on a CameraDevice instance to close the connection with the camera. Any subsequent call to the camera device will throw exception errors.

Run in Worker Thread

Some camera operations such as opening a camera take a long while to complete. If such operation is executed from the UI thread, the UI might be stopped. Consider opening the camera in a separate thread if your application takes a while to open the camera device.

Constraints on Camera Resolution

On some LG smartphones, resolution constraints are imposed on the dual camera devices when the dual cameras are opened at the same time.

 

The following models support full resolution (wide-angle: 8MP + normal-angle: 16MP) when using dual cameras:

F700L, F700S, F700K, VS987, H820 LS992, H830SV, US992, AS992, RS988, H831, H860, H850, H850TR, H850K, H858, H850AR, H820PR, H868, H860N

 

The following models support half resolution (wide-angle: 8MP + normal-angle: 8MP) when using dual cameras:

H840, H845, H840TR, H840AR, H848, H845N

Navigation