Android Development Camera Tutorial

posted in: Android, Tutorial | 0

In this Android development camera tutorial we take a look at using your Android device’s camera to capture a photo and then display that photo in an ImageView in your Android Activity.

Setting Up Your Android Camera Intent

We first need to tell the Android OS that we’re using the camera feature and ask the user permission to gain access to their camera. We do this by placing the appropriate uses-feature and uses-permission xml tags in our Android manifest file. We place this outside the “application” tag.

Camera icon

Then, create an implicit intent for the camera activity, tell the camera activity where to store the file by putting a string in the intent’s extras bundle and start the activity using the startActivityForResult method. The camera activity will use the file location string to put the resulting camera image at that location. So, give it a unique name, usually by adding a time stamp, and a “jpg” extension and the camera activity will handle the rest.

Finally, in the overridden activityForResult method, check to see if the resultCode is RESULT_OK and access the image at the image location you originally passed with the camera intent. You can load the image in a Bitmap object and use that Bitmap object to set that image in an ImageView’s image bitmap. All images are stored in a public directory, accessible by your application. Make sure to clean these out so your app doesn’t bloat the user’s device with unnecessary data.

There’s a lot more details in the video below. Don’t forget to subscribe to the Electronic Armory’s YouTube channel for more videos, or sign up to our mailing list with the form to the left.YouTube Subscription button

Be sure to download the source code here:

Electronic Armory Android Camera Tutorial Source Code

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.