0% found this document useful (0 votes)
10 views6 pages

Android Camera App Tutorial Guide

This document provides instructions for creating an Android application that launches the device's built-in camera and displays the captured image. It describes laying out the app interface with buttons and image views, launching the camera app with an intent, and handling the returned result to display the captured photo. It also explains how to enforce that the app requires a camera by adding metadata to the Android manifest.

Uploaded by

yorveh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views6 pages

Android Camera App Tutorial Guide

This document provides instructions for creating an Android application that launches the device's built-in camera and displays the captured image. It describes laying out the app interface with buttons and image views, launching the camera app with an intent, and handling the returned result to display the captured photo. It also explains how to enforce that the app requires a camera by adding metadata to the Android manifest.

Uploaded by

yorveh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd

Android Introduction

Camera

@2011 Mihail L. Sichitiu 1


Many thanks to Jun Bum Lim for his help
with this tutorial.
Goal
 Create an application that launches the
built-in Camera and use the results for
displaying the captured image.

@2010 Mihail L. Sichitiu 2


Layout
 Make a LinearLayout with
 a TextView,
 a Button, and
 an ImageView
 Create a handler for the OnClick event of
the Button

@2010 Mihail L. Sichitiu 3


Launch Camera
 Creating an Intent, as follows, within your button click
handler:
Intent cameraIntent = new Intent([Link].ACTION_IMAGE_CAPTURE);

 Launch camera activity with asking result:

startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);  

 define within your application as the request code


returned by the Camera image capture Intent
private static final int CAMERA_PIC_REQUEST = 1; 

@2010 Mihail L. Sichitiu 4


Handling result from Camera
 By adding onActivityResult() in your Activity:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    if (requestCode == CAMERA_PIC_REQUEST) {

// display image   
        Bitmap thumbnail = (Bitmap) [Link]().get("data");
ImageView imageTakePic = (ImageView) findViewById([Link]);
[Link](thumbnail);
    }  

@2010 Mihail L. Sichitiu 5


Enforcing Device Requirement

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="[Link]
package="[Link]"
Application wants a
android:versionCode="1"
camera
android:versionName="1.0">
It is not enforced by
<uses-sdk android:minSdkVersion="7" />
Android
<uses-feature android:name="[Link]"></uses-feature>

<application android:icon="@drawable/icon" android:label="@string/app_name">


<activity android:name=".AndroidCameraActivity"
android:label="@string/app_name">
<intent-filter>
:
:

@2010 Mihail L. Sichitiu 6

You might also like