Mad Experiment 6

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

MAD EXPERIMENT 6

NAME: KAUSHIK LANJEWAR

CSE'B'(A) 09

Q1.

Xml code1-

<uses-permission android:name="android.permission.CAMERA"/>

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<application

... >

<activity android:name=".MainActivity">

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

</application>

Xml code2

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:gravity="center"

android:padding="16dp">

<Button

android:id="@+id/btn_open_camera"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="Open Camera" />

<ImageView

android:id="@+id/imageView"

android:layout_width="300dp"

android:layout_height="300dp"

android:layout_marginTop="20dp"

android:contentDescription="Captured Image"

android:scaleType="centerCrop"

android:background="#E0E0E0"/>

</LinearLayout>

Java code-

package com.example.camerademo;

import android.content.Intent;

import android.graphics.Bitmap;

import android.os.Bundle;

import android.provider.MediaStore;

import android.widget.Button;

import android.widget.ImageView;

import android.widget.Toast;

import androidx.annotation.Nullable;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

private static final int REQUEST_IMAGE_CAPTURE = 1;

private ImageView imageView;

private Button btnOpenCamera;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

imageView = findViewById(R.id.imageView);
btnOpenCamera = findViewById(R.id.btn_open_camera);

btnOpenCamera.setOnClickListener(v -> {

// Open Camera using Intent

Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

if (cameraIntent.resolveActivity(getPackageManager()) != null) {

startActivityForResult(cameraIntent, REQUEST_IMAGE_CAPTURE);

} else {

Toast.makeText(MainActivity.this, "Camera app is not available!",

Toast.LENGTH_SHORT).show();

});

@Override

protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {

super.onActivityResult(requestCode, resultCode, data);

if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {

Bundle extras = data.getExtras();

Bitmap imageBitmap = (Bitmap) extras.get("data");

imageView.setImageBitmap(imageBitmap);

Q2.

Xml code1-

<uses-permission android:name="android.permission.BLUETOOTH" />

<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

<uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Xml code2-

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:padding="16dp"

android:gravity="center">

<Button

android:id="@+id/btn_enable_bluetooth"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Enable Bluetooth" />

<Button

android:id="@+id/btn_disable_bluetooth"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Disable Bluetooth"

android:layout_marginTop="10dp"/>

<Button

android:id="@+id/btn_discover_devices"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Discover Devices"

android:layout_marginTop="10dp"/>

<ListView

android:id="@+id/lv_paired_devices"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="20dp"

android:dividerHeight="1dp"/>

</LinearLayout>
Java code-

You might also like