Skip to end of metadata
Go to start of metadata

Overview

This tutorial will walk you through a basic app that allows the user to access the mobile device's camera and shoot pictures and videos. We will cover a generic project setup, set device permissions, and create a small app that allows for taking pictures.

Project setup

Start with creating an empty Alloy project by executing this command: appc new

Permissions

For Android, the build system will automatically add the needed "android.permission.CAMERA" and "android.permission.WRITE_EXTERNAL_STORAGE" permissions to the AndroidManifest.xml for you. So, you don't need to edit the tiapp.xml file.

For iOS, you need to add the following key(s) to the tiapp.xml:

Say cheese

It is time to open the camera! We add a simple button to our view and add a click event to it, so we can open the camera.

Simple button

The below code implements the button click event to request camera permission (if not currently granted) and then show the camera.

Click event

The showCamera() method has some properties you can set to change some options and to get the image. For a full list, please review CameraOptionsType API documentation.

You can also add a custom overlay to the camera with the overlay property which is assigned a view. When doing this, you have to display your own buttons to take a picture or cancel out and use the Ti.Media.takePicture() and Ti.Media.hideCamera() functions. On Android, using an overlay will display an in-app camera activity instead of displaying the default camera app installed on the device for taking photos.

 

This tutorial was adapted from https://devblog.axway.com/mobile-apps/from-zero-to-app-with-a-camera/ which was originally written by Michael Gangolf