0% found this document useful (0 votes)
30 views

Ayush Experiment 23

The document contains code for two programs that capture images and videos using the device camera and display them. The first program captures an image using the camera intent and displays it in an ImageView. The second program captures a video using the camera intent, gets the video Uri, and plays it in a VideoView. Both programs handle the result of the camera intent and update the views accordingly.
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)
30 views

Ayush Experiment 23

The document contains code for two programs that capture images and videos using the device camera and display them. The first program captures an image using the camera intent and displays it in an ImageView. The second program captures a video using the camera intent, gets the video Uri, and plays it in a VideoView. Both programs handle the result of the camera intent and update the views accordingly.
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/ 5

Practical 23

Exercise Q1. Write a program to capture an image and display it using image view.
XML:

<Button
<?xml version="1.0" encoding="utf- android:layout_width="w
8"?>
rap_content"
<LinearLayout
xmlns:android="http://schemas.android.c android:layout_height="
om/apk/res/android"
wrap_content"
xmlns:app="http://schemas.android.
android:id="@+id/openca
com/apk/res-auto"
mbtn"
xmlns:tools="http://schemas.androi
android:text="Open
d.com/tools"
Camera"/>
android:layout_width="match_pare
<ImageView
nt"
android:layout_width="w
android:layout_height="match_pare
rap_content"
nt" tools:context=".exp23_ex1"
android:layout_height="
android:orientation="vertical"
wrap_content"
android:gravity="center">
android:id="@+id/image

v"

android:layout_margin="

10dp"/>
</LinearLayout>
Activity;

Java:
import android.content.Intent;
package com.example.exp23;
import
import androidx.annotation.Nullable; android.graphics.Bitmap;
import import android.os.Bundle;
androidx.appcompat.app.AppCompat
import
i1 = findViewById(R.id.imagev);
android.provider.Media
b1.setOnClickListener(new
Store; import
View.OnClickListener() {
android.view.View; @Override
import public void
onClick(View view)
android.widget.Button; { Intent camera =
import new
Intent(MediaStore.ACTION_IMA
android.widget.ImageV
GE_CAPTURE);
iew;
startActivityForResult(cam

era,7);
public class exp23_ex1 extends
}
AppCompatActivity { Button b1;
});
ImageVie
}
w i1;

@Overr @Override

ide protected void


onActivityResult(int requestCode,
protected void onCreate(Bundle int resultCode, @Nullable Intent
data) {
savedInstanceState)
super.onActivityResult(requestCode,
{ super.onCreate(savedInstanceSt
resultCode, data); if(requestCode ==
ate);
7)
setContentView(R.layout.activity
{
_exp23_ex1);
Bitmap photo =
b1 =
(Bitmap)data.getExtras().get("data"
findViewById(R.id.opencambtn);
); i1.setImageBitmap(photo);

}
}
}
Exercise Q2. Write a program to capture an image and display it using image view.

XML: rap_content"

android:layout_height="wrap_
<?xml version="1.0" encoding="utf-
8"?> content"
<LinearLayout
xmlns:android="http://schemas.android.c android:id="@+id/opencambtn
om/apk/res/android"
" android:text="Open
xmlns:app="http://schemas.android.
Camera"/>
com/apk/res-auto"
<VideoView
xmlns:tools="http://schemas.androi
android:layout_width="wrap_c
d.com/tools"
ontent"
android:layout_width="match_pare
android:layout_height="wrap_
nt"
content"
android:layout_height="match_pare
android:id="@+id/videov"
nt" tools:context=".exp23_ex2"
android:layout_margin="10dp"
android:orientation="vertical"
/>
android:gravity="center">
<Button
</LinearLayout>
android:layout_width="w
VideoVie

Java: w v1; Uri


package com.example.exp23; uri = null;

@Overrid
import androidx.annotation.Nullable;
e
import
androidx.appcompat.app.AppCompatAct protected void onCreate(Bundle
savedInstanceState) {
ivity;

import

android.content.

Intent; import

android.graphics

.Bitmap; import

android.net.Uri;

import android.os.Bundle;
import

android.provider.M

ediaStore; import

android.view.View

import

android.widget.B

utton; import

android.widget.Vi

deoView;

public class exp23_ex2

extends AppCompatActivity

{Button b1;
super.onCreate(savedInstanceStat

e);

setContentView(R.layout.activity

_exp23_ex2); b1 =

findViewById(R.id.opencambtn);

v1 = findViewById(R.id.videov);

b1.setOnClickListener(new

View.OnClickListener() {

@Override
public void
onClick(View view) {
Intent intent = new
Intent(MediaStore.ACTION_VIDEO
_CAPTURE);
startActivityForResult(intent,7);
}
});

}
@Override
protected void onActivityResult(int
requestCode, int resultCode, @Nullable
Intent data) {
super.onActivityResult(requestCode,

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


{
uri =

data.getData();

v1.setVideoUR

I(uri);

v1.start();

}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy