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.
Start with creating an empty Alloy project by executing this command:
For Android, the build system will automatically add the needed
"android.permission.WRITE_EXTERNAL_STORAGE" permissions to the
AndroidManifest.xml for you. So, you don't need to edit the
For iOS, you need to add the following key(s) to the
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.
The below code implements the button click event to request camera permission (if not currently granted) and then show the camera.
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.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