Mad Experiment 6
Mad Experiment 6
Mad Experiment 6
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>
</intent-filter>
</activity>
</application>
Xml code2
<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"
<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;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = findViewById(R.id.imageView);
btnOpenCamera = findViewById(R.id.btn_open_camera);
btnOpenCamera.setOnClickListener(v -> {
if (cameraIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(cameraIntent, REQUEST_IMAGE_CAPTURE);
} else {
Toast.LENGTH_SHORT).show();
});
@Override
imageView.setImageBitmap(imageBitmap);
Q2.
Xml code1-
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
Xml code2-
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"
<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-