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

Android Guide With Imtiaz Saifullah: Email: Ping/Text: +92-331-7370872

This document provides instructions on how to use the camera in Android applications. It discusses using the android.hardware.camera2 API and camera intents to capture images and videos. It provides code samples to launch the camera via an intent on a button click, and handle the result in onActivityResult to display the captured image in an ImageView.

Uploaded by

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

Android Guide With Imtiaz Saifullah: Email: Ping/Text: +92-331-7370872

This document provides instructions on how to use the camera in Android applications. It discusses using the android.hardware.camera2 API and camera intents to capture images and videos. It provides code samples to launch the camera via an intent on a button click, and handle the result in onActivityResult to display the captured image in an ImageView.

Uploaded by

Ali Hassan Naqvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Imtiaz

Saifullah

Android Guide
with
Imtiaz Saifullah
Email: [email protected]
FB: facebook.com/ImtiazSaif.Khan
Ping/Text: +92-331-7370872
Imtiaz
Saifullah

Android Using Camera


Imtiaz
Saifullah Android Using Camera
Camera is useful to capture the photos and videos in our applications. By using camera api we can control the
functionalities of camera based on our requirements.
The android framework provides a two ways such as android.hardware.camera2 api and camera intent to capture
the images and videos in our application.

By using startActivityForResult() method with intent action
parameter MediaStore.ACTION_IMAGE_CAPTURE, we can take the pictures from our android
applications.
 

Intent cInt = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);


startActivityForResult(cInt,Image_Capture_Code);

Innovative Sun (Software Development Academy) | Imtiaz Saifullah | +92-331-7370872


Imtiaz
Saifullah Android Using Camera
we create an application, open activity_main.xml file from \res\layout folder path and write the code like as
shown below.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<Button
android:id="@+id/btnTakePicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Take a Photo"
android:textStyle="bold"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/capturedImage"
android:layout_above="@+id/btnTakePicture"/>
</RelativeLayout>

Innovative Sun (Software Development Academy) | Imtiaz Saifullah | +92-331-7370872


Imtiaz
Saifullah Android Using Camera
we create an application, open activity_main.xml file from \res\layout folder path and write the code like as
shown below.
public class MainActivity extends AppCompatActivity {
private Button btnCapture;
private ImageView imgCapture;
private static final int Image_Capture_Code = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnCapture =(Button)findViewById(R.id.btnTakePicture);
imgCapture = (ImageView) findViewById(R.id.capturedImage);
btnCapture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent cInt = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cInt,Image_Capture_Code);
} }); }
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent
data) {
if (requestCode == Image_Capture_Code) {
if (resultCode == RESULT_OK) {
Bitmap bp = (Bitmap) data.getExtras().get("data");
imgCapture.setImageBitmap(bp);
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
}} }}

Innovative Sun (Software Development Academy) | Imtiaz Saifullah | +92-331-7370872


Imtiaz
Saifullah

You might also like