0% found this document useful (0 votes)
14 views4 pages

Exp 23

The document describes two Android applications: one for capturing and displaying an image, and another for recording a video. The first application uses an ImageView and a button to initiate the camera, while the second application uses a button to start video recording. Both applications include layout XML and Java code for functionality, developed by Harsh Maghnani.
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)
14 views4 pages

Exp 23

The document describes two Android applications: one for capturing and displaying an image, and another for recording a video. The first application uses an ImageView and a button to initiate the camera, while the second application uses a button to start video recording. Both applications include layout XML and Java code for functionality, developed by Harsh Maghnani.
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/ 4

Exp23_1: Write a program to capture an image and display it using image view.

Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/img"
android:layout_width="420dp"
android:layout_height="400dp"/>
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Capture and Set Image"
android:textSize="25dp"
android:layout_gravity="center"
android:layout_marginTop="30dp"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="~Developed By Harsh.Maghnani (Roll no:06)"
android:textColor="#0000FF"
android:textSize="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginBottom="35dp"
android:layout_marginEnd="35dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java:
package com.example.exp23_1;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
Button b1;
ImageView imageView;
int CAMERA_REQUEST=1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = findViewById(R.id.btn);
imageView = findViewById(R.id.img);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, CAMERA_REQUEST);
}
});
}
@Override
protected void onActivityResult(int requestcode,int res,@Nullable
Intent data){
super.onActivityResult(requestcode,res,data);
if (requestcode==CAMERA_REQUEST)
{
Bitmap image= (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(image);
}
}
}
Output:-
Exp23_2: Write a program to record a video using various camera methods
Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Capture Video"
android:textSize="25dp"
android:layout_gravity="center"
android:layout_marginTop="30dp"
/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="~Developed By Harsh.Maghnani (Roll no:06)"
android:textColor="#0000FF"
android:textSize="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginBottom="35dp"
android:layout_marginEnd="35dp" />

</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java:
package com.example.exp23_2;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


Button b1;
int VIDEO_REQUEST=1;
Uri videoUri=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = findViewById(R.id.btn);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(i, VIDEO_REQUEST);
}
});
}
@Override
protected void onActivityResult(int requestcode,int res,@Nullable
Intent data){
super.onActivityResult(requestcode,res,data);
if (requestcode==VIDEO_REQUEST)
{
videoUri=data.getData();
Toast.makeText(getApplicationContext(),"Video Captured
Successfully:"+videoUri.toString(),Toast.LENGTH_LONG).show();
}
}
}
Output:-

You might also like