- A "Take Picture" button on our main activity, when the user clicks it, the device camera will be shown that will enable your user the take a picture.
- After taking a picture, the preview of the image will be shown with options to "Save" or "Discard" the image.
- If the user tapped "Save", the image will be saved on the directory we specified in our code, else, if the user tapped "Discard", the device camera will be shown again.
- If the user saved the image, he will be asked if he wants to take another picture.
|Using Device Camera To Get Pictures For Your App|
You may download the code here:
Our MainActivity.java code - This activity will show our "Take Picture" button.
Our res/layout/activity_main.xml - The XML layout file for our MainActivity.
Our CameraActivity.java - This code does almost all the operations from starting the device camera to saving the image to specified directory.
Our res/layout/camera.xml code - XML I used for our CameraActivity.java activity
The AndroidManifest.xml code - This will give us permission to use the device camera hardware.
Some output screenshots: