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

Android Camera & Video Capture Guide

The document describes two programs to build a camera app. The first program allows a user to capture an image and display it in an ImageView. The second program allows a user to record a video using various camera methods and display it in a VideoView. Both programs use intents and onActivityResult to launch the camera, capture media, and return the results to the app for display.

Uploaded by

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

Android Camera & Video Capture Guide

The document describes two programs to build a camera app. The first program allows a user to capture an image and display it in an ImageView. The second program allows a user to record a video using various camera methods and display it in a VideoView. Both programs use intents and onActivityResult to launch the camera, capture media, and return the results to the app for display.

Uploaded by

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

MAD Experiment 23

Aim: Develop a program to build Camera

IX. Exercise
1. Write a program to capture an image and display it

using image view. activity_main.xml


It contains an Imageview named ‘imageView’ and a Button named
‘btnCamera’

MainActivity.java

package

com.example.expt23_1;

import

androidx.annotation.Nulla

ble;

import

androidx.appcompat.app.AppCompatActivi

ty; import android.content.Intent;

import

android.graphics.Bitmap;

import android.os.Bundle;

import

android.provider.MediaS

tore; import

android.view.View;

import

android.widget.Button;

import

android.widget.ImageVi

ew;

public class MainActivity extends


AppCompatActivity { ImageView im1;
Button btnCamera;
final int

CAM_REQUEST=1

23; @Override

protected void onCreate(Bundle

savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

im1=findViewById(R.id.imageView);

btnCamera=findViewById(R.id.btnCamera);

btnCamera.setOnClickListener(new

View.OnClickListener() {

@Override
public void onClick(View v) {
Intent i= new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

startActivityForResult(i,CAM_REQUEST);
}
});
}

@Override
protected void onActivityResult(int requestCode, int resultCode,

@Nullable Intent data) { super.onActivityResult(requestCode,

resultCode, data); if(requestCode==CAM_REQUEST)


{
Bitmap

bmp=(Bitmap)data.getExtras().get("

data"); im1.setImageBitmap(bmp);
}
}
}

2. Write a program to record a video using various camera

methods. activity_main.xml

It contains an VideoView named ‘videoView’ and a Button named


‘btnCamera’
MainActivity.java
package

com.example.expt23_2;

import

androidx.annotation.Nulla

ble;

import

androidx.appcompat.app.AppCompat

Activity; import

android.content.Intent;

import

android.net.Uri;

import

android.os.Bundle;

import

android.provider.MediaS

tore; import

android.view.View;
import android.widget.VideoView;
public class MainActivity extends

AppCompatActivity { final int

VIDEO_REQUEST=444;

Uri uri;

VideoVi

ew v1;
@Override
protected void onCreate(Bundle

savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
v1= findViewById(R.id.videoView);
}
public void captureV(View v)
{
Intent i = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);

startActivityForResult(i,VIDEO_REQUEST);
}

@Override
protected void onActivityResult(int requestCode, int resultCode,

@Nullable Intent data) { super.onActivityResult(requestCode,

resultCode, data); if(requestCode==VIDEO_REQUEST)

{
uri=data.getD

ata();

v1.setVideoUR

I(uri);

v1.start();
}
}
}

You might also like