App Inventor Extensions


Camera Extension

See the App Inventor Extensions document about how to use an App Inventor Extension.

For questions about this extension or bug reports please start a new thread in the App Inventor community. Thank you.

For feature requests please contact me by email. To be a sponsor of a new method already is possible starting from only 10 USD! With your contribution you will help the complete App Inventor community. Thank you.

Mar 20th, 2017: Version 2: Initial Version released

May 1st, 2017: Version 3: new properties for exposure compensation and white balance added

Oct 10th, 2018: Version 4: new properties for zoom added

Jan 31st, 2019: Version 5: SDK 26 release: new events PermissionGranted and Permission Denied added

Jul 13st, 2020: Version 6: bugfix for SupportedFlashModes (could return null),
new properties: UseCameraIndex, CameraIndex, new methods: NumberOfCameras, IsCameraBackfacing,
permission logic simplified, developer is now responsible to ask for permission

Description

Camera extension to take a picture programmatically without user interaction.
Required permission: android.permission.CAMERA, android.permission.WRITE_EXTERNAL_STORAGE
Minimum API Level to use for this extension is API Level 11 (Android 3.0).

Notes

Properties


Specifies whether camera index should be used.

Note: If the camera index will be used, then the property UseFrontCamera will be ignored.


Returns Camera Index. Possible values between 1 and the number of cameras of the device.


Specifies Camera Index. Possible values between 1 and the number of cameras of the device. If an invalid value is entered, the default value will be used. Default value is 1.


Returns File name of taken picture.


Specifies File name of taken picture. Default value is /Pictures/picture.jpg.
Please see Q2 how to set the filename starting from SDK30!


Returns Flash mode. See also method SupportedFlashModes.


Specifies Flash mode. Default value is auto. See also method SupportedFlashModes.


Returns Focus mode. See also method SupportedFocusModes.


Specifies Focus mode. Default value is auto. See also method SupportedFocusModes.


Returns Quality of taken picture.


Specifies Quality of taken picture. Possible values between 0 and 100. 0 meaning compress for small size, 100 meaning compress for max quality. Default value is 80.


Returns whether front camera should be used.


Specifies whether front camera should be used. Default value is False. DEPRECATED! Use CameraIndex together with IsCameraBackfacing to select a camera facing to the back or to the front.

Note: If the camera index will be used, then the property UseFrontCamera will be ignored. Therefore if you still like to use the old logic to set the property UseFrontCamera to true, then you have to set the UseCameraIndex property to false, too.


Returns width. See also method SupportedPictureSizes.


Specifies width. Default value is 0, i.e. default width of camera will be used. See also method SupportedPictureSizes.


Returns height. See also method SupportedPictureSizes.


Specifies height. Default value is 0, i.e. default height of camera will be used. See also method SupportedPictureSizes.


Returns whether device is ready to take a picture (readyToTakePicture = true) or process of taking a picture is already in progress (readyToTakePicture = false).


Returns whether Warnings should be suppressed.


Specifies whether Warnings should be suppressed.


Get Exposure Compensation Index. The range is from MinExposureCompensation to MaxExposureCompensation. 0 means exposure is not adjusted.


Minimum exposure compensation index (<=0). If both this method and ExposureCompensationMax return 0, exposure compensation is not supported.


Maximum exposure compensation index (>=0). If both this method and ExposureCompensationMin return 0, exposure compensation is not supported.


Set Exposure Compensation Index. The range is from MinExposureCompensation to MaxExposureCompensation. 0 means exposure is not adjusted. Set this to a lower value and the image gets darker, set this to a larger value and the image gets brighter. Default value is 0.


Return a single string with all the camera parameters. This can be used for test purposes.


Returns White Balance. See also method SupportedWhiteBalance.


Specifies White Balance. Default value is auto. See also method SupportedWhiteBalance.


Returns Zoom Ratio. See also method SupportedZoomRatios.


Specifies Zoom Ratio. Default value is 0. See also method SupportedZoomRatios.


Returns Max. Zoom Ratio.

Methods


Take Picture programmatically without user interaction.
Note: This process takes takes a few seconds. Don't move the device while taking the photo.


Get supported picture sizes of the device.
Returns a list of supported picture sizes of the device. The width and height is delimited by x, for example 640x480. You can set the width and height of the picture to take in property Width and Height. If you choose a width-height combination, which is not supported by the device, then the next lower width-height combination will be used.


Get supported flash modes of the device.
Returns a list of supported flash modes of the device. You can set the flash mode in property FlashMode. If you choose a flash mode, which is not supported by the device, then auto will be used.


Get supported focus modes of the device.
Returns a list of supported focus modes of the device. You can set the focus mode in property FocusMode. If you choose a focus mode, which is not supported by the device, then auto will be used.


Get supported white balance of the device.
Returns a list of supported white balance of the device. You can set the white balance in property WhiteBalance.


Get supported zoom ratios of the device.
Returns a list of supported zoom ratios of the device. You can set the zoom ratio in property Zoom.


Return the number of cameras.


Is Camera backfacing, returns true or false.

Events


Event indicating that picture has been taken.
in Version 6: parameter cameraIndex added.


Event indicating that an error occurred.


Event has been removed in Version 6. Developer is now responsible to ask for permission. Please see the test projects about how to do it.


Event has been removed in Version 6. Developer is now responsible to ask for permission. Please see the test projects about how to do it.

Example App: Camera Extension Test

Example App: Time Lapse

The example project takes a picture using the front camera each 3 seconds. After 3 pictures are taken, a time lapse video of the 3 taken pictures will be displayed.



Test and Minor Known Issues (Version 6)

Test and Minor Known Issues (Version 1 - 5)

Questions and Answers

Q1: I would like to use the barcode scanner component to scan using the front camera. Can I use the camera exension to switch to the front camera for this?
A: Unfortunately this is not possible like that because the barcode scanner component always first selects the background camera before scanning. However I have something else for you. I once tried to create a barcode scanner extension to add some properties to the barcode scanner component. That extension offers a property to use the front camera which works together with the external scanner only. See screenshot about how to use it.

This solution does not work together with the internal scanner, therefore I never published it. But in case you are interested in that extension I can send it to you after having received a small donation via Paypal. Just mention in the comments that you want me to send you the barcodescanner extension with front camera. Thank you.

Q2: How to save image in another storage location or with different name, can you give example for the block?
A: Starting with the SDK30 Android restricts accessing the file system. Therefore you have to store the image in the ASD now... in my file extension you can find a method for that.

Up to SDK29 it was possible to store something in an arbitrary directory. Starting from SDK30 unfortunately this is not possible anymore. We only have access to the ASD and shared storage, i.e. for photos the folder /DCIM and /Pictures. To copy or move a taken picture to the shared storage, please use the new file component. Note: currently as of August 30, 2021 there are still some bugs in the file component which have to be fixed, see for example this thread..

For questions about App Inventor,
please ask in the App Inventor community.Thank you.

Test the functionality of the Camera extension

Both test apps are available in Google Play. You can test the examples following these steps

  1. Follow the opt-in URL for the camera test app and the opt-in URL for the timelapse test app to get access to the apps and to be able to download them to your device. It might take a few hours for Google to enable you as beta tester!
  2. Start testing.

Buy the Camera extension for App Inventor


You can buy this extension (aix file).
With your payment you accept the terms and conditions below.

Payment options

1. Paypal

Please transfer 12 USD via Paypal
to Pura Vida Apps

2. Bitcoin

After having received your payment I will be happy to send the download link to you. Please let me know your Google account! I usually will send the download link not later than 24 hours after having received your payment.
Thank you! Taifun


Terms and Conditions

Back to top of page ...


Home | Snippets | Tutorials | Extensions | Links | Search | Privacy Policy | Contact