Main Content


Connection to camera on Android device


A camera object represents a connection to a camera on an Android™ device. After you create the object, you can acquire images from the camera using Object Functions.




cam = camera(m,name) connects to the camera specified by name on the Android device m.

Input Arguments

expand all

Android mobile device connection, specified as a mobiledev object.

Camera name, specified as 'back' or 'front'. Valid camera names are listed in the AvailableCameras property of the mobiledev object.

Example: cam = camera(m,'front') creates a connection to the front-facing camera of the Android device represented by the mobiledev object m.


expand all

This property is read-only.

Camera name, returned as 'back' or 'front'. The 'back' camera is the rear-facing camera on the back of the phone. The 'front' camera is the front-facing camera on the side of the display.

Data Types: char | string

This property is read-only.

Available resolutions of the camera, returned as a cell array of strings. Possible resolutions are '640x480' and '1280x720'. If the device camera does not support either of these resolutions, the closest supported resolution is selected.

Data Types: cell

Camera resolution, returned as a character vector or string scalar. Valid values are listed in the AvailableResolutions property. You can set the camera resolution using dot notation.

Example: cam.Resolution = '1280x720' sets the camera resolution to 1280-by-720.

Data Types: char | string

Camera flash mode, specified as 'auto', 'on', or 'off'. This property is only available for cameras that support flash. You can set the flash mode using dot notation.

Example: cam.Flash = 'off' turns off flash.

Data Types: char | string

Camera autofocus mode, specified as 'on' or 'off'. This property is only available for cameras that support autofocus. You can set the autofocus mode using dot notation.

Example: cam.Autofocus = 'off' turns off autofocus.

Data Types: char | string

Object Functions

snapshotAcquire single image frame from Android device camera


collapse all

This example assumes that you have already installed and set up MATLAB® Mobile™ on your Android device and connected to the MathWorks® Cloud. For more information about these steps, see Install MATLAB Mobile on Your Device and Sign In to the Cloud.

Start MATLAB Mobile on your Android device.

On the Commands screen of MATLAB Mobile, create a mobiledev object m.

m = mobiledev
m = 
mobiledev with properties:

                   Connected: 1
            AvailableCameras: {'back' 'front'}
                     Logging: 0
            InitialTimestamp: ''

   AccelerationSensorEnabled: 0
AngularVelocitySensorEnabled: 0
       MagneticSensorEnabled: 0
    OrientationSensorEnabled: 0
       PositionSensorEnabled: 0

Supported functions

The AvailableCameras property indicates that this device has both 'back' and 'front' cameras.

Create a connection to the 'back' camera of the device.

cam = camera(m,'back')
cam = 
  Camera with properties:

                    Name: 'back'
    AvailableResolutions: {'640x480'  '1280x720'}
              Resolution: '640x480'
                   Flash: 'off'
               Autofocus: 'on'

Creating the connection returns the camera object and its properties.

Version History

Introduced in R2019a