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

MADPractical No.23

The document contains two exercises related to Android development, specifically focusing on capturing images and recording videos using the camera. Each exercise includes an XML layout file and a corresponding Java class for the main activity, demonstrating how to initiate camera actions and handle results. The first exercise captures images, while the second exercise is designed for video recording.

Uploaded by

ashokgupta3460
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)
4 views

MADPractical No.23

The document contains two exercises related to Android development, specifically focusing on capturing images and recording videos using the camera. Each exercise includes an XML layout file and a corresponding Java class for the main activity, demonstrating how to initiate camera actions and handle results. The first exercise captures images, while the second exercise is designed for video recording.

Uploaded by

ashokgupta3460
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/ 3

Practical No.

23
Exercise
Q.1
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<ImageView
android:id="@+id/i1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b1"
android:text="Click Me"
android:onClick="Display"/>
</LinearLayout>
MainActivity.java
package com.example.pr23;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.ImageView;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class MainActivity extends AppCompatActivity {
private static final int CAMERA_REQUEST=1886;
ImageView iv1;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv1=(ImageView)findViewById(R.id.i1);

}
public void Display(View v)
{
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i,CAMERA_REQUEST);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==CAMERA_REQUEST)
{
Bitmap photo = (Bitmap)data.getExtras().get("data");
iv1.setImageBitmap(photo);
}
}
}
Output:

Q.2
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b1"
android:text="Record Video"
android:onClick="Display"/>
</LinearLayout>
MainActivity.java
package com.example.pr23;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.ImageView;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class MainActivity extends AppCompatActivity {
private static final int CAMERA_REQUEST=1886;
ImageView iv1;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void Display(View v)
{
Intent i = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(i,CAMERA_REQUEST);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
}
}
Output:

You might also like