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

Mobile Application Development lab file

This document is a practical file for the Mobile Application Development course at Guru Gobind Singh Indraprastha University, detailing various practical assignments for BCA students. It includes tasks such as configuring Android Studio, creating simple applications like a 'Hello World' app, a calculator, and apps demonstrating Android lifecycle phases. Each practical outlines the project structure, code snippets, and expected outputs for the assignments.

Uploaded by

Tushar Tikia
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)
25 views

Mobile Application Development lab file

This document is a practical file for the Mobile Application Development course at Guru Gobind Singh Indraprastha University, detailing various practical assignments for BCA students. It includes tasks such as configuring Android Studio, creating simple applications like a 'Hello World' app, a calculator, and apps demonstrating Android lifecycle phases. Each practical outlines the project structure, code snippets, and expected outputs for the assignments.

Uploaded by

Tushar Tikia
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/ 108

GURU GOBIND SINGH INDRAPRASTHA UNIVERSITY

INSTITUTE OF INNOVATION IN TECHNOLOGY & MANAGEMENT

MOBILE APPLICATION DEVELOPMENT

PRACTICAL FILE

BCAP-318

Nurturing Excellence

Submitted To: Submitted By:

Mr.Kanhaiya Lal Name: Tushar Tikia


(Assistant Professor) Class: BCA VI M1
Enrolment no: 02590302022
INDEX

Programme:BCA Semester:VI Paper Code:BCAP-318 Academic Year:2024-

S. Practicals Page. No Sign.


No

1 Configure Android Studio for Android


Mobile Application Development.

2 Create "hello world" application to display


"hello world" in the middle of the screen in
the emulator as well as android phone

3 Create an android app to display various


android lifecycle phases.

4 Create a calculator app that performs


addition, subtraction, division, and
multiplication operation on numbers.

5 Write an Android application to convert into


different currencies for example, Rupees to
dollar

6 Write an android application to draw 2D


graphics primitives.

7 Write an application to record video and


audio on topic “Intent” and play the audio
and video.
Write an android application to Get data
8
from Restfull API and show
into Recycler View.
9 Create a login application to verify username
and password. On successful login, redirect
to another activity that has a textview to
display "welcome user" with logout button.
On click of logout button, adialog should
appear with ok and cancel buttons. On click
of oK button, go back to the login activity and
on click of cancel button, stay on the same
activity.

10 Write an application to mark the daily route


of travel in map.

11 Create an application to pick up any image


from the native application gallery and
display it on the screen

12 Create an application to perform the


operations of create, insert, delete, view and
update, using sqlite database.

13 Read phonebook contacts using content


providers and display in list.

14 Create an application that uses checkbox for


construction of a shopping list so the user can
check off items as they are picked up. The
checked items should be displayed in a
textview control.
Create an application to take picture using
15
native application.
Practical-1
Configure Android Studio for Android Application Development.
Name: Tushar Tikia Roll no: 02590302022 Sem: VI Course: BCA

Download Android Studio


Open any web browser and navigate to the Android Studio download page.
This is the Android Developers website, where you can download Android
Studio. This page automatically detects your operating system.
Click Download Android Studio. The Terms and Conditions page with the
Android Studio License Agreement opens.
Read the License Agreement.
At the bottom of the page, if you agree with the terms and conditions, select the I
have read and agree with the above terms and conditions checkbox.
Click Download Android Studio to start the download.
When prompted, save the file to a location where you can easily locate it, such as
the Downloads folder.
Wait for the download to complete. This may take a while and may be a good
moment to enjoy some tea!

Install Android Studio on Windows


Open the folder where you downloaded and saved the Android Studio installation
file.
Double-click the downloaded file.
If you see a User Account Control dialog about allowing the installation to
make changes to your computer, click Yes to confirm the installation.
The Welcome to Android Studio Setup dialog displays

Click Next to start the installation.


Accept the default installation settings for all steps.
Click Finish when the installation is done to launch Android Studio.
Choose your preference of light or dark theme when Android Studio first
launches. Screenshots in this Sem use the light theme, but choose whichever one
you prefer.

During the installation, the setup wizard downloads and installs additional
components and tools needed for Android app development. This may take some
time depending on your internet speed. During this time, you may see a User
Account Control dialog for Windows Command Processor. Click Yes to
accept the dialog.

9. You may also receive a Windows Security Alert about adb.exe. Click Allow
Access, if needed, to continue the installation.

When the download and installation completes, click Finish.


The Welcome to Android Studio window displays and you're ready to start
creating apps
Get to know the Android Studio UI
The Android Studio main window consists of several logical areas, shown in
Figure 1.
Figure 1. The Android Studio main window.
1. Toolbar: Carry out a wide range of actions, including running your app and
launching Android tools.
2. Navigation bar: Navigate through your project and open files for editing. It
provides a more compact view of the structure visible in the Project window.
3. Editor window: Create and modify code. Depending on the current file type,
the editor can change. For example, when viewing a layout file, the editor
displays the Layout Editor.
4. Tool window bar: Use the buttons on the outside of the IDE window to
expand or collapse individual tool windows.
5. Tool windows: Access specific tasks like project management, search,
version control, and more. You can expand them and collapse them.
6. Status bar: Display the status of your project and the IDE itself, as well as
any warnings or messages.
Create your first Android app

1. Before you begin

Install Android Studio on your computer if you haven't done so already. Check
that your computer meets the system requirements required for running Android
Studio (located at the bottom of the download page). If you need more detailed
instructions on the setup process, refer to the Download and install Android
Studio codelab.
In this codelab, you create your first Android app with a project template
provided by Android Studio.

2. Create a project using the template

In this codelab, you create an Android app with the Empty Activity project
template provided by Android Studio.
To create a project in Android Studio:
1. Double click the Android Studio icon to launch Android Studio.
2. In the Welcome to Android Studio dialog, click New Project.

The New Project window opens with a list of templates provided by Android
Studio

In Android Studio, a project template is an Android project that provides the


blueprint for a certain type of app. Templates create the structure of the project
and the files needed for Android Studio to build your project. The template that
you choose provides starter code to get you going faster.
3. Make sure the Phone and Tablet tab is selected.
4. Click the Empty Activity template to select it as the template for your project.
The Empty Activity template is the template to create a simple project that you
can use to build a Compose app. It has a single screen and displays the
text "Hello Android!".
5. Click Next. The New Project dialog opens. This has some fields to configure
your project.
6. Configure your project as follows:
The Name field is used to enter the name of your project, for this codelab type
"Greeting Card".
Leave the Package name field as is. This is how your files will be organized in
the file structure. In this case, the package name will
be com.example.greetingcard.
Leave the Save location field as is. It contains the location where all the files
related to your project are saved. Take a note of where that is on your computer
so that you can find your files.
Select API 24: Android 7.0 (Nougat) from the menu in the Minimum
SDK field. Minimum SDK indicates the minimum version of Android that your
app can run on.
Practical-2
Create "hello world" application to display "hello world" in the middle of the screen.
in the emulator as well as android phone
Name: Tushar Tikia Roll no: 02590302022 Sem: VI Course: BCA

Project structure

MainActivity.java
package com.example.myapp;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

}
}
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">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
OUTPUT
Practical-3
Create an android app to display various android lifecycle phases.
Name: Tushar Tikia Roll no: 02590302022 Sem: VI Course: BCA

Project Structure

Android activity life cycle diagram


AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Android_Life_Cycle"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>

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">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

MainActiviy.java
package com.example.android_life_cycle;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("Event","In the onCreate() event");
}

@Override
protected void onStart() {
super.onStart();
Log.d("Event","In the onStart() event");
}

@Override
protected void onRestart() {
super.onRestart();
Log.d("Event","In the onRestart() event");
}

@Override
protected void onResume() {
super.onResume();
Log.d("Event","In the onResume() event");
}

@Override
protected void onPause() {
super.onPause();
Log.d("Event","In the onPause() event");
}

@Override
protected void onStop() {
super.onStop();
Log.d("Event","In the onStop() event");
}

@Override
protected void onDestroy() {
super.onDestroy();
Log.d("Event","In the onDestroy() event");
}
}
OUTPUT
Practical-4
Create a calculator app that performs addition, subtraction, division and multiplication
operation on numbers
Name: Tushar Tikia Roll no: 02590302022 Sem: VI Course: BCA

Project Structure

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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<EditText
android:id="@+id/editTextText"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_margin="10sp"
android:textSize="30sp"
android:textStyle="bold"
android:gravity="center"
android:inputType="text"
android:text="Enter num1 " />

<EditText
android:id="@+id/editTextText2"
android:layout_width="match_parent"
android:layout_height="103dp"
android:layout_margin="10sp"
android:inputType="text"
android:gravity="center"
android:textStyle="bold"
android:textSize="30sp"
android:text="Enter num2" />

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="82dp"
android:textSize="30sp"
android:textStyle="bold"
android:gravity="center"
android:layout_margin="10sp"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"/>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="378dp">

<Button
android:id="@+id/button6"
android:layout_width="175dp"
android:layout_height="79dp"
android:onClick="onClick"
android:layout_marginLeft="10dp"
android:text="+" />

<Button
android:id="@+id/button7"
android:layout_width="186dp"
android:layout_height="81dp"
android:layout_alignRight="@id/button6"
android:layout_marginEnd="-223dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="-192dp"
android:layout_marginStart="-223dp"
android:onClick="onClick"
android:text="-" />

<Button
android:id="@+id/button8"
android:layout_width="175dp"
android:layout_height="75dp"
android:onClick="onClick"
android:layout_marginLeft="10dp"
android:layout_alignBottom="@id/button6"
android:layout_marginBottom="-88dp"
android:text="*" />

<Button
android:id="@+id/button9"
android:layout_width="192dp"
android:layout_height="73dp"
android:onClick="onClick"
android:layout_alignBottom="@id/button8"
android:layout_alignRight="@id/button8"
android:layout_marginRight="-225dp"
android:text="/" />
</RelativeLayout>
</LinearLayout>

MainActivity.Java
package com.example.calculatorapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements


View.OnClickListener {
public Button add,sub,mul,div;
public EditText num1,num2;
public TextView result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
add=findViewById(R.id.button6);
sub=findViewById(R.id.button7);
mul=findViewById(R.id.button8);
div=findViewById(R.id.button9);
num1=findViewById(R.id.editTextText);
num2=findViewById(R.id.editTextText2);
result=findViewById(R.id.textView);
add.setOnClickListener(MainActivity.this);
sub.setOnClickListener(MainActivity.this);
mul.setOnClickListener(MainActivity.this);
div.setOnClickListener(MainActivity.this);
}
@Override
public void onClick(View v) {

String s1=num1.getText().toString().trim();
String s2=num2.getText().toString().trim();
int n1=Integer.parseInt(s1);
int n2=Integer.parseInt(s2);
if (v.getId()==R.id.button6)
{
result.setText(String.valueOf(n1+n2));
}
else if (v.getId()==R.id.button7)
{
result.setText(String.valueOf(n1-n2));
}
else if (v.getId()==R.id.button8)
{
result.setText(String.valueOf(n1*n2));
}else
{
result.setText(String.valueOf(n1/n2));
}
}
}
OUTPUT
ADDITION SUBTRACTION

MULTIPLICATION DIVISION
Practical-5
Write an Android application to convert into different currencies for example, Rupees
to dollar
Name: Tushar Tikia Roll no: 02590302022 Sem: VI Course: BCA

Project Structure

activity_main.xml

<?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">

<!-- Input Amount -->


<EditText
android:id="@+id/editTextAmount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Amount"
android:inputType="numberDecimal" />

<!-- Currency Selection -->


<Spinner
android:id="@+id/spinnerCurrency"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp" />

<!-- Convert Button -->


<Button
android:id="@+id/btnConvert"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Convert" />

<!-- Converted Amount -->


<TextView
android:id="@+id/textViewResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Converted Amount: "
android:textSize="18sp" />
</LinearLayout>
MainActivity.java

package com.example.currencyapp;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import java.util.HashMap;

public class MainActivity extends AppCompatActivity{

private EditText editTextAmount;


private Spinner spinnerCurrency;
private TextView textViewResult;
private HashMap<String, Double> currencyRates;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextAmount = findViewById(R.id.editTextAmount);
spinnerCurrency = findViewById(R.id.spinnerCurrency);
textViewResult = findViewById(R.id.textViewResult);
Button btnConvert = findViewById(R.id.btnConvert);
initializeCurrencyRates();
// Set up Spinner with currency options
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_spinner_item, currencyRates.keySet().toArray(new
String[0]));

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item
);
spinnerCurrency.setAdapter(adapter);
btnConvert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
convertCurrency();
}
});
}
private void initializeCurrencyRates() {
// Example rates: 1 USD to other currencies
currencyRates = new HashMap<>();
currencyRates.put("USD", 1.0); // Base currency
currencyRates.put("EUR", 0.85); // Euro
currencyRates.put("INR", 74.50); // Indian Rupee
currencyRates.put("GBP", 0.75); // British Pound
currencyRates.put("JPY", 110.0); // Japanese Yen
}
private void convertCurrency() {
String amountText = editTextAmount.getText().toString().trim();
if (amountText.isEmpty()) {
Toast.makeText(this, "Please enter an amount",
Toast.LENGTH_SHORT).show();
return;
}

double amount = Double.parseDouble(amountText);


String selectedCurrency = spinnerCurrency.getSelectedItem().toString();
double conversionRate= currencyRates.getOrDefault(selectedCurrency,1.0);
double convertedAmount = amount * conversionRate;
textViewResult.setText(String.format("Converted Amount: %.2f %s",
convertedAmount, selectedCurrency));
}
}
OUTPUT
Practical-6
Write an android application to draw 2D graphics primitives.
Name: Tushar Tikia Roll no: 02590302022 Sem: VI Course: BCA

Project Structure

activity_main.xml

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


<RelativeLayout 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">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>

MainActivity.Java

package com.example.graphicsprimitives;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Bitmap bg=Bitmap.createBitmap(720,1280,Bitmap.Config.ARGB_8888);
ImageView img=findViewById(R.id.imageView);
img.setBackgroundDrawable(new BitmapDrawable(bg));

Canvas canvas=new Canvas(bg);

Paint paint=new Paint();


paint.setColor(Color.RED);
paint.setTextSize(50);

canvas.drawText("Rectangle",420,150,paint);
canvas.drawRect(400,200,650,700,paint);

Paint paintC=new Paint();


paintC.setColor(Color.MAGENTA);
paintC.setTextSize(50);

canvas.drawText("Circle",120,150,paintC);
canvas.drawCircle(200,350,150,paintC);

Paint paintS=new Paint();


paintS.setColor(Color.GREEN);
paintS.setTextSize(50);

canvas.drawText("Square",120,800,paintS);
canvas.drawRect(50,850,350,1150,paintS);

Paint paintL=new Paint();


paintL.setColor(Color.GRAY);
paintL.setTextSize(50);

canvas.drawText("Line",480,800,paintL);
canvas.drawLine(520,850,520,1150,paintL);

}
}
OUTPUT
Practical-7
Write an application to record video and audio on topic “Intent” and play
the audio and video.
Name: Tushar Tikia Roll no: 02590302022 Sem: VI Course: BCA

Project Structure

AndroidManifest.xml

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<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
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
activity_main.xml

<?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">

<Button
android:id="@+id/btnRecordAudio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Record Audio" />

<Button
android:id="@+id/btnPlayAudio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Play Audio" />

<Button
android:id="@+id/btnStopAudio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Stop Audio" />
<Button
android:id="@+id/btnRecordVideo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Record Video" />
<Button
android:id="@+id/btnPlayVideo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Play Video" />

<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

dialog_audio_player.xml

<?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="wrap_content"
android:orientation="vertical"
android:padding="16dp"
android:background="@color/white">

<TextView
android:id="@+id/tvAudioTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Playing Audio"
android:textColor="@color/design_default_color_primary"
android:textSize="38sp"
android:textStyle="bold"
android:gravity="center"
android:paddingBottom="10dp" />

</LinearLayout>

MainActivity.java

package com.example.multimediaapp;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.app.Dialog;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;
import java.io.IOException;

public class MainActivity extends AppCompatActivity {

private static final int REQUEST_AUDIO_PERMISSION = 200;


private static final int REQUEST_CAMERA_PERMISSION = 201;
private static final int REQUEST_VIDEO_CAPTURE = 2;
private static final String AUDIO_FILE_NAME = "audio_record.3gp";
private String file;
private MediaRecorder mediaRecorder;
private Uri videoUri;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar();
Button btnRecordAudio = findViewById(R.id.btnRecordAudio);
Button btnPlayAudio = findViewById(R.id.btnPlayAudio);
Button btnStopAudio = findViewById(R.id.btnStopAudio);
Button btnRecordVideo = findViewById(R.id.btnRecordVideo);
Button btnPlayVideo = findViewById(R.id.btnPlayVideo);
btnRecordAudio.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (checkAudioPermission()) {
startAudioRecording();
}
}
});
btnPlayAudio.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
playAudio();
}
});
btnStopAudio.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
stopAudioRecording();
}
});
btnRecordVideo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

if(checkCameraPermission()) {

recordVideo();
}
}
});
btnPlayVideo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
playVideo();
}
});
}
private void startAudioRecording() {
try {
file=getExternalFilesDir(null).getAbsolutePath()+"/"+AUDIO_FILE_NAME;
mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);

mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setOutputFile(file);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mediaRecorder.prepare();
mediaRecorder.start();
Toast.makeText(this, "Recording started", Toast.LENGTH_LONG).show();
findViewById(R.id.btnRecordAudio).setEnabled(false);
findViewById(R.id.btnPlayAudio).setEnabled(false);
} catch (IOException e) {
Toast.makeText(this, "Error starting recording",
Toast.LENGTH_SHORT).show();
}
}
private boolean checkAudioPermission() {
if (ContextCompat.checkSelfPermission(getApplicationContext(),
android.Manifest.permission.RECORD_AUDIO) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this, new
String[]{android.Manifest.permission.RECORD_AUDIO},
REQUEST_AUDIO_PERMISSION);
return false;
}
return true;
}
private boolean checkCameraPermission() {
if (ContextCompat.checkSelfPermission(this,
android.Manifest.permission.CAMERA) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new
String[]{android.Manifest.permission.CAMERA},
REQUEST_CAMERA_PERMISSION);
return false;
}
return true;
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions,int[]
grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQUEST_AUDIO_PERMISSION) {
if (grantResults.length > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
startAudioRecording();
} else {
Toast.makeText(this, "Audio recording permission denied",
Toast.LENGTH_SHORT).show();
}
} else if (requestCode == REQUEST_CAMERA_PERMISSION) {
if (grantResults.length > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
recordVideo();
} else {
Toast.makeText(this, "Camera permission denied",
Toast.LENGTH_SHORT).show();
}
}
}
private void stopAudioRecording() {
mediaRecorder.stop();
mediaRecorder.release();
mediaRecorder = null;
Toast.makeText(this, "Audio recorded successfully!",
Toast.LENGTH_SHORT).show();

findViewById(R.id.btnRecordAudio).setEnabled(true);
findViewById(R.id.btnPlayAudio).setEnabled(true);
}
private void playAudio() {
MediaPlayer mediaPlayer = new MediaPlayer();
try {
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.dialog_audio_player);
dialog.setCancelable(true);
mediaPlayer.setDataSource(file);
mediaPlayer.prepare();
mediaPlayer.start();
dialog.show();
//Toast.makeText(this, "Playing audio...", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
}

private void recordVideo() {


Intent videoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (videoIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(videoIntent, REQUEST_VIDEO_CAPTURE);
} else {
Toast.makeText(this, "No app available to record video",
Toast.LENGTH_SHORT).show();
}
}

private void playVideo() {


if (videoUri != null) {
VideoView videoView = findViewById(R.id.videoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setVideoURI(videoUri);
videoView.start();
} else {
Toast.makeText(this, "No video recorded yet!",
Toast.LENGTH_SHORT).show();
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_VIDEO_CAPTURE && data != null) {
videoUri = data.getData();
Toast.makeText(this, "Video saved: " + videoUri,
Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(this, "Recording cancelled", Toast.LENGTH_SHORT).show();
}
}
}
OUTPUT
Practical-8
Write an android application to Get data from Restful API and show
into Recycler View.
Name: Tushar Tikia Roll no: 02590302022 Sem: VI Course: BCA

Project Structure

API

Api_url="https://script.googleusercontent.com/macros/echo?user_content_key=-
YemyYERKU2NntsOnxEsMbq-
k wTp8QGIl8k12DLppJ6fHGXwm3vbMlhQ_oRh6qEOZZ8cHzbgl8mkaVu_t5-
Hdn3ulv3CqYm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_1xSncGQajx_ryfhECjZEnC
uc_Pn9Cxnt48ZBoIFC7D9gRL1wVLOPg4YxskhimYX1vggPmB9aX5rGFjdxHh8RnC
HFsvQxoarvNaNLlLwb7d4YEF7r07ETew&lib=M1mjq6zUNrplWb13hM0gtWzcFR0
BbGMzm"
{

"data": [

"Books_Title": "C The Complete Reference",

"Books_link":
"https://drive.google.com/file/d/1MXFGPkpOZCu9zhh1SrpHkjawYXBebKBE/view?u
sp=drivesdk",

"Books_Images":
"https://drive.google.com/uc?id=15NrgaImBvs4B1sYpKs_uMx9QxWvlcdRX"

},

"Books_Title": "C++ The complete reference",

"Books_link":
"https://drive.google.com/file/d/0B1V9nCjFdTUybGx1N3NaVXhFTlpzREJ0WDh4NE
ZkNnVrcUpZ/view?usp=drivesdk",

"Books_Images":
"https://drive.google.com/uc?id=15V3xbfvGWVXz53NfOE7VLUohW_cUAt9g"

},

"Books_Title": "Java The Complete reference",

"Books_link":
"https://drive.google.com/file/d/1VmA2UebcZXANctUFipyPF55_vXcdoCGz/view?usp
=drivesdk",

"Books_Images":
"https://drive.google.com/uc?id=15UvN5enfWGpdMirWB3Ol2gMzzLqZatQC"

},

"Books_Title": "C# The complete reference",


"Books_link": "https://drive.google.com/file/d/1Y68ukI-
8bMK7DdbQWV1v7IB1AFGZ_8v1/view?usp=drivesdk",

"Books_Images":
"https://drive.google.com/uc?id=16DKkLExlzf5Jj6sF_9Wc2y8xB6A29nAK"

},

"Books_Title": "Learning Python ",

"Books_link":
"https://drive.google.com/file/d/102QYfPjqsW17MzXdc545c6WQrmztZTH3/view?usp
=drivesdk",

"Books_Images": "https://drive.google.com/uc?id=15R0S_MziOiVmnY-
xSTulSzGkEcqGEhi0"

},

"Books_Title": "Learning R",

"Books_link":
"https://drive.google.com/file/d/1vnn3doDAklqSsV4SKBJzrCU341QfMb5S/view?usp=
drivesdk",

"Books_Images":
"https://drive.google.com/file/d/16Nzt2V5_8zqOaqFyPwjh33ayG3X-
wwyC/view?usp=drivesdk"

},

"Books_Title": "Introduction to Machine Learning using Python",

"Books_link":
"https://drive.google.com/file/d/11v58nCKrDwYQlZtl3FF1IXnHAFTo0ia3/view?usp=d
rivesdk",

"Books_Images": "https://drive.google.com/file/d/16a9aMmYQyQ3vezab-
QgV16Jd4GanYyy0/view?usp=drivesdk"

},

{
"Books_Title": "Artificial intelligence a modern approach",

"Books_link": "https://drive.google.com/file/d/1TfBUIH-
rkFyaFhVmbV_jU6XKOfzNPa9e/view?usp=drivesdk",

"Books_Images":
"https://drive.google.com/file/d/16cOHsGWlcGTwwu1FL9mnnOc71yIGX-
bs/view?usp=drivesdk"

},

"Books_Title": "Introduction to Automata Theory",

"Books_link":
"https://drive.google.com/file/d/1WuHGOZf8IadhhYhIgVJEGAQnoHaeouog/view?us
p=drivesdk",

"Books_Images":
"https://drive.google.com/file/d/16jlCbrJIwIJTCFG8avWttYtVr8h1Id4J/view?usp=dri
vesdk"

},

"Books_Title": "Compiler principles Techniques and Tools",

"Books_link":
"https://drive.google.com/file/d/19f8nEWp8goK2oJ0K9MSB479Otb5RyPl1/view?usp=
drivesdk",

"Books_Images":
"https://drive.google.com/file/d/16f4N7yVavCrSZKQeQutp40xaZh9VLTAW/view?usp
=drivesdk"

},

"Books_Title": "Operating system concept",

"Books_link":
"https://drive.google.com/file/d/1hNCYEBzS0IM_gltTpTx4y4vJYwl2kNnH/view?usp=
drivesdk",

"Books_Images": "https://drive.google.com/file/d/16jy50KET_My_x-
1SHkRLDpBgDJ3l2N_D/view?usp=drivesdk"
},

"Books_Title": "Python for data analysis",

"Books_link": "https://drive.google.com/file/d/1v6EE4XNaHzH2-
Gy3oPbRxWu228seZPHq/view?usp=drivesdk",

"Books_Images": "https://drive.google.com/file/d/16uFwnCbfD-
dljY57M42UngomOgapoNHk/view?usp=drivesdk"

},

"Books_Title": "Python Data Science Handbook",

"Books_link":
"https://drive.google.com/file/d/1mc5hKCDqqZgDNPG_T62h6CrDgTPuyd1M/view?us
p=drivesdk",

"Books_Images": "https://drive.google.com/file/d/16kv-
krQGzxVV2q7QTrPbbtSxmchB5UHN/view?usp=drivesdk"

},

"Books_Title": "Data Structure using C",

"Books_link": "https://drive.google.com/file/d/1rd3gETlyCk3-
jjqEfCxp5kQ1F1ae9auB/view?usp=drivesdk",

"Books_Images": "https://drive.google.com/file/d/17-lcjA9aWEpMnQo-
npsNQJnBudcKKTMu/view?usp=drivesdk"

},

"Books_Title": "Computer system architecture",

"Books_link": "https://drive.google.com/file/d/1aAk-
lSi_3sZfyLaepolIuTqq9CWocxuZ/view?usp=drivesdk",

"Books_Images": "https://drive.google.com/file/d/170tXLhFvtP1E_EVKmQ-
Z3gLiC1ng4sEX/view?usp=drivesdk"

},
{

"Books_Title": "Fundamentals of database system",

"Books_link":
"https://drive.google.com/file/d/1FW38D_GQKAcbxWL1Qb1kn4DFKzHy2yGw/view?
usp=drivesdk",

"Books_Images":
"https://drive.google.com/file/d/1766PJ_HHdtqITz8sMykPmF7ZNfXR6JBE/view?usp
=drivesdk"

},

"Books_Title": "Database system concept",

"Books_link": "https://drive.google.com/file/d/1WtYGOX6w2gw-
SEas3OjvsMK2Lgeek4xy/view?usp=drivesdk",

"Books_Images":
"https://drive.google.com/file/d/176g9t8XsCjVHLWRapAS7SnsBBADogns4/view?usp=
drivesdk"

},

"Books_Title": "Data communication networking",

"Books_link":
"https://drive.google.com/file/d/1dJBuon5J7WdMXKLY3Ryk624dZq9v5HQl/view?us
p=drivesdk",

"Books_Images": "https://drive.google.com/file/d/17BcJMm-
O4dEV20xvsqvkY7UvaLaWh_Yp/view?usp=drivesdk"

},

"Books_Title": "Graph Theory",

"Books_link": "https://drive.google.com/file/d/1Wp-
DtX3G6Y0bucfGxHJPeSu3vbwqqfMK/view?usp=drivesdk",

"Books_Images": "https://drive.google.com/file/d/17ByLlMc5Aj_hhNLNeFnHB-
BB55ICRkLI/view?usp=drivesdk"
},

"Books_Title": "Operation Research",

"Books_link": "https://drive.google.com/file/d/1d6wH7XyD-
_bdgSOm6S4owmo0u3Xp8azi/view?usp=drivesdk",

"Books_Images": "https://drive.google.com/file/d/17MofJ1lmCtub2dTodyTY2R-
KQq_IStZ4/view?usp=drivesdk"

},

"Books_Title": "Discrete Mathematics",

"Books_link": "https://drive.google.com/file/d/1Bc95NNlmdg-
EcvkVSbhowuWMJCRe5Cqd/view?usp=drivesdk",

"Books_Images":
"https://drive.google.com/file/d/17I2e7c59N8kAAQl3k5iFBscQGvZXAEPd/view?usp=
drivesdk"

},

"Books_Title": "Discrete mathematics and it's Application",

"Books_link":
"https://drive.google.com/file/d/1lPt5kPOAtPEzmrst1ZhI1BuS4ptZlnw7/view?usp=dri
vesdk",

"Books_Images":
"https://drive.google.com/file/d/17MeE25IdGiRRETDvo1kYhvwQiic3CWsi/view?usp=
drivesdk"

},

"Books_Title": "Discrete mathematics with Application",

"Books_link": "https://drive.google.com/file/d/1Jwn-
LOlFASBD40_wldqFfpsos6fDX31F/view?usp=drivesdk",
"Books_Images":
"https://drive.google.com/file/d/17JCtZxEMewuW3LdbUulMjQrcL4nQSBJV/view?us
p=drivesdk"

},

"Books_Title": "Introduction to Algorithm",

"Books_link": "https://drive.google.com/file/d/1d9iyg_r-HrXgaCK2-3F3waPLmZ6-
Jhce/view?usp=drivesdk",

"Books_Images": "https://drive.google.com/file/d/17Sns5d-LzUmqh_y1KQ-
OcEUkA28No6RC/view?usp=drivesdk"

},

"Books_Title": "Data Mining Concept and Techniques",

"Books_link":
"https://drive.google.com/file/d/17A9LSvfGhX1Sr1NWyN4JQFDjR_VPAfuq/view?usp
=drivesdk",

"Books_Images": "https://drive.google.com/file/d/17W8-TX6eGNR0ZH7PWEq2-
XhJDecmu3Ev/view?usp=drivesdk"

},

"Books_Title": "Hands on machine learning with tensorflow and scikitlearn",

"Books_link":
"https://drive.google.com/file/d/1gVuzlxJoBy1GvzQGbPsKWXEe5AYAipjM/view?usp
=drivesdk",

"Books_Images": "https://drive.google.com/file/d/17X-
aTDeWhLDb8aRQXdbNBeMrOAMle8VX/view?usp=drivesdk"

},

"Books_Title": "Microprocessor Architecture, Programming and Applications


with 8085",
"Books_link":
"https://drive.google.com/file/d/1YbqTeykmVetg5MBfGyCXzXS84gVydxTR/view?usp
=drivesdk",

"Books_Images":
"https://drive.google.com/file/d/17_vfCMHnK24b6K8ZVHu5d10tborsGFU9/view?usp
=drivesdk"

},

"Books_Title": "Computer Graphics C version",

"Books_link":
"https://drive.google.com/file/d/13gHYz89kFkO9uoFWklh8qmcY_Qqp_lXi/view?usp=
drivesdk",

"Books_Images":
"https://drive.google.com/file/d/17gaXvuuDLkwARomL5SZsiEe8cf_bMyjW/view?usp
=drivesdk"

},

"Books_Title": "Programming php",

"Books_link": "https://drive.google.com/file/d/1c5Nph8wBgCyTjWlrKjfxiz-
j6zpZqknY/view?usp=drivesdk",

"Books_Images":
"https://drive.google.com/file/d/18bxiVw80bAtT2bA_UKyGX_ekm64939Qn/view?usp=
drivesdk"

},

"Books_Title": "Computer organization and architecture designing for


performance",

"Books_link":
"https://drive.google.com/file/d/1pnXIumxEwFjQnmyd8v5T0LYmjxbKgHmO/view?us
p=drivesdk",

"Books_Images":
"https://drive.google.com/file/d/18dtnTtr_Gu4j1hMFjHGs5sCks7VC1e2E/view?usp=d
rivesdk"
},

"Books_Title": "Cryptography and Network security Principles and Practices",

"Books_link": "https://drive.google.com/file/d/1Dx4KyirAE_6JE-
IgP9rnRMPtYFauj9yY/view?usp=drivesdk",

"Books_Images":
"https://drive.google.com/file/d/18eh7FJu5dfNv02LgrTsTqka2rhuM0NKq/view?usp=d
rivesdk"

},

"Books_Title": "Julia programming language",

"Books_link":
"https://drive.google.com/file/d/13puvU1gHhc0pmvowzqgY27sMI4XoJ5xq/view?usp=d
rivesdk",

"Books_Images":
"https://drive.google.com/file/d/18v4UASpwCn0YwMIF11Gx_tvKoTT4qRNw/view?us
p=drivesdk"

},

"Books_Title": "Kotlin Programming",

"Books_link": "https://drive.google.com/file/d/1940Oo97_PbNhHfQ29xwAQ_-
IND39re1f/view?usp=drivesdk",

"Books_Images":
"https://drive.google.com/file/d/197mZsPG1GFmxFGP03ur51Ab3haJRdtsu/view?usp=
drivesdk"

}
AndroidManifest.xml

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.VolleyJsonParsing"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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


</intent-filter>
</activity>
</application>

</manifest>

build.gradle.kts(Module:app)

plugins {
id("com.android.application")
}

android {
namespace = "com.example.volleyjsonparsing"
compileSdk = 34

defaultConfig {
applicationId = "com.example.volleyjsonparsing"
minSdk = 21
targetSdk = 34
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}

dependencies {

implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.11.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("com.android.volley:volley:1.2.1")
implementation("androidx.recyclerview:recyclerview:1.3.2")
// For control over item selection of both touch and mouse driven selection
implementation("androidx.recyclerview:recyclerview-selection:1.1.0")
implementation("androidx.cardview:cardview:1.0.0")
implementation ("com.github.bumptech.glide:glide:4.12.0")
implementation ("com.squareup.picasso:picasso:2.8")
// Glide v4 uses this new annotation processor -- see
https://bumptech.github.io/glide/doc/generatedapi.html
annotationProcessor ("com.github.bumptech.glide:compiler:4.12.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
}
activity_main.xml

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


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<ToggleButton
android:id="@+id/tButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textOff="OFF"
android:textOn="ON" />

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_View"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</LinearLayout>

item_list.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="5dp"
app:cardBackgroundColor="@color/design_default_color_primary"
tools:ignore="MissingDefaultResource">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/bookTitle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="@color/white"
android:textSize="25sp"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
Book_Adapter.java
package com.example.volleyjsonparsing;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.List;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class Book_Adapter extends


RecyclerView.Adapter<Book_Adapter.BookHolder> {
public List<BooK_Model>booKModelList;
public Context context;
public Book_Adapter(Context context,List<BooK_Model> booKModelList) {
this.booKModelList = booKModelList;
this.context=context;
}

@NonNull
@Override
public BookHolder onCreateViewHolder(@NonNull ViewGroup parent, int
viewType) {
View view= LayoutInflater.from(context).inflate(R.layout.item_list,parent,false);
return new BookHolder(view);
}

@Override
public void onBindViewHolder(@NonNull BookHolder holder, int position) {
BooK_Model k_model=booKModelList.get(position);
holder.book_title.setText(k_model.getBook_name());
}

@Override
public int getItemCount() {
return booKModelList.size();
}

public class BookHolder extends RecyclerView.ViewHolder


{
public TextView book_title;

public BookHolder(@NonNull View itemView) {


super(itemView);
book_title=itemView.findViewById(R.id.bookTitle);
}
}
}
MainActivity.java
package com.example.volleyjsonparsing;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.ToggleButton;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

public String
url="https://script.googleusercontent.com/macros/echo?user_content_key=-
YemyYERKU2NntsOnxEsMbq-
k wTp8QGIl8k12DLppJ6fHGXwm3vbMlhQ_oRh6qEOZZ8cHzbgl8mkaVu_t5-
Hdn3ulv3CqYm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_1xSncGQajx_ryfhECjZEnC
uc_Pn9Cxnt48ZBoIFC7D9gRL1wVLOPg4YxskhimYX1vggPmB9aX5rGFjdxHh8RnC
HFsvQxoarvNaNLlLwb7d4YEF7r07ETew&lib=M1mjq6zUNrplWb13hM0gtWzcFR0
BbGMzm";
public RequestQueue requestQueue;
public List<BooK_Model> booKModelList;
public RecyclerView recyclerView;
public Book_Adapter bookAdapter;
public ToggleButton toggleButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
requestQueue= Volley.newRequestQueue(this);
booKModelList=new ArrayList<BooK_Model>();
recyclerView=findViewById(R.id.recycler_View);
toggleButton=findViewById(R.id.tButton);
toggleButton.setOnCheckedChangeListener(new
CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean
isChecked) {
if (isChecked) {
recyclerView.setLayoutManager(new
LinearLayoutManager(MainActivity.this));
}else{
recyclerView.setLayoutManager(new
GridLayoutManager(MainActivity.this,2));
}
}
});
getJson(url);
}
public void getJson(String url)
{
JsonObjectRequest jsonObjectRequest=new
JsonObjectRequest(Request.Method.GET, url, null, new
Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray=response.getJSONArray("data");
for (int i=0;i<jsonArray.length();i++)
{
JSONObject object=jsonArray.getJSONObject(i);
String title=object.getString("Books_Title");
booKModelList.add(new BooK_Model(title));
}
bookAdapter=new Book_Adapter(MainActivity.this,booKModelList);
recyclerView.setAdapter(bookAdapter);
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
requestQueue.add(jsonObjectRequest);
}
}
OUTPUT
Practical-9
Create a login application to verify username and password. On successful
login, redirect to another activity that has a textview to display "welcome
user" with logout button. On click of logout button, adialog should appear
with ok and cancel buttons. On click of oK button, go back to the login
activity and on click of cancel button, stay on the same activity.
Name: Tushar Tikia Roll no: 02590302022 Sem: VI Course: BCA

Project Structure

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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/design_default_color_secondary"
android:layout_margin="10dp"
android:orientation="vertical"
android:layout_gravity="center">

<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:textAlignment="center"
android:textSize="35sp" />

<EditText
android:id="@+id/userpass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberPassword"
android:textAlignment="center"
android:textSize="35sp" />

<Button
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="71dp"
android:text="Login"
android:textSize="35sp" />
</LinearLayout>
</LinearLayout>

MainActivity.java

package com.example.loginlogoutapp;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {


public Button login;
public EditText user,pass;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
login=findViewById(R.id.login);
user=findViewById(R.id.username);
pass=findViewById(R.id.userpass);
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String user_name=user.getText().toString();
String user_pass=pass.getText().toString();
if(user_name.equals("admin")&&user_pass.equals("12345")) {
Intent intent=new Intent(MainActivity.this,MainActivity2.class);
startActivity(intent);
}
}
});
}
}

activity_main2.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="vertical"
android:layout_gravity="center">
<ImageView
android:id="@+id/iitm_imag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/iitm" />

<TextView
android:id="@+id/welcomsg"
android:layout_width="match_parent"
android:layout_height="51dp"
android:gravity="center"
android:textStyle="bold"
android:text="WELCOME"
android:textSize="35sp" />
<Button
android:id="@+id/logout"
android:layout_width="match_parent"
android:layout_height="71dp"
android:text="Logout"
android:textSize="35sp" />
</LinearLayout>
</LinearLayout>

MainActivity2.java

package com.example.loginlogoutapp;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity2 extends AppCompatActivity {

public Button logout;


public TextView msg;
public ImageView view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
logout=findViewById(R.id.logout);
msg=findViewById(R.id.welcomsg);
view=findViewById(R.id.iitm_imag);
logout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(MainActivity2.this,MainActivity.class);
startActivity(intent);
}
});
}
}
OUTPUT
Practical-10
Write an application to mark the daily route of travel in map.
Name: Tushar Tikia Roll no: 02590302022 Sem: VI Course: BCA

Project Structure

Manifest.xml

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission
android:name="android.permission.ACCESS.NETWORK.STATE"/>
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.TravelApp"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyCvxA-i89A875DQaYtYw-ITaVeAOo68Pzk"/>
</application>

</manifest>
activity_main.xml

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


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- Map View -->


<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>

MainActivity.java

package com.example.travelapp;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.FragmentActivity;
import android.Manifest;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.location.Location;
import android.os.Bundle;
import android.os.Looper;
import android.widget.Toast;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationCallback;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationResult;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.location.Priority;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.Polyline;
import com.google.android.gms.maps.model.PolylineOptions;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements


OnMapReadyCallback {

private GoogleMap mMap;


private FusedLocationProviderClient fusedLocationClient;
private LocationCallback locationCallback;
private List<LatLng> routePoints = new ArrayList<>();
private LatLng currentLatLng;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Initialize the map


SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager()
.findFragmentById(R.id.map);
if (mapFragment != null) {
mapFragment.getMapAsync(this);
}

// Initialize location services


fusedLocationClient =
LocationServices.getFusedLocationProviderClient(MainActivity.this);
setupLocationTracking();
}
@Override
public void onMapReady(@NonNull GoogleMap googleMap) {
mMap = googleMap;
// Check for location permissions
if (ActivityCompat.checkSelfPermission(getApplicationContext(),
android.Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION},
1);
//return;
}
mMap.setMyLocationEnabled(true);
}

private void setupLocationTracking() {


// Check for location permissions
if (ActivityCompat.checkSelfPermission(getApplicationContext(),
Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
//return;
}

// Request location updates


LocationRequest locationRequest = null;
if (android.os.Build.VERSION.SDK_INT >=
android.os.Build.VERSION_CODES.S) {
locationRequest = new
LocationRequest.Builder(Priority.PRIORITY_HIGH_ACCURACY).setMinUpdateInt
ervalMillis(5000).build();
}

locationCallback = new LocationCallback() {


@Override
public void onLocationResult(@NonNull LocationResult locationResult) {
for (Location location : locationResult.getLocations()) {
currentLatLng = new LatLng(location.getLatitude(),
location.getLongitude());
routePoints.add(currentLatLng);
}
updateRouteOnMap();
}
};
fusedLocationClient.requestLocationUpdates(locationRequest,locationCallback,
null);
}

private void updateRouteOnMap() {


if (mMap == null|| routePoints.isEmpty())return;
// Draw the route on the map
PolylineOptions polylineOptions = new PolylineOptions()
.addAll(routePoints)
.width(5)
.color(Color.RED);
mMap.addPolyline(polylineOptions);

mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(routePoints.get(routePo
ints.size() - 1), 15));
for(int i=0;i<routePoints.size()-1;i++){
LatLng src=routePoints.get(i);
LatLng dest=routePoints.get(i+1);
mMap.addPolyline(
new PolylineOptions().add(
new LatLng(src.latitude,src.longitude),
new LatLng(dest.latitude,dest.longitude)
).width(2).color(Color.BLUE).geodesic(true)
);
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[]
permissions,
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 1) {
if (grantResults.length > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
setupLocationTracking();
} else {
Toast.makeText(this, "Permission denied", Toast.LENGTH_SHORT).show();
}
}
}

@Override
protected void onDestroy() {
super.onDestroy();
if (fusedLocationClient != null && locationCallback != null) {
fusedLocationClient.removeLocationUpdates(locationCallback);
}
}
}
OUTPUT
Practical-11
Create an application to pick up any image from the native application
gallery and display it on the screen
Name: Tushar Tikia Roll no: 02590302022 Sem: VI Course: BCA

Project Structure

AndroidManifest.xml

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.GallaryApp"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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


</intent-filter>
</activity>
</application>

</manifest>

Activity_main.xml

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


<RelativeLayout 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">

<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:srcCompat="@drawable/ic_launcher_background"
tools:layout_editor_absoluteX="6dp"
tools:layout_editor_absoluteY="7dp" />

<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_below="@id/imageView"
android:text="Select_Image" />
</RelativeLayout>

MainActivity.java

package com.example.gallaryapp;

import android.app.Activity;
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.ImageView;
import android.widget.Toast;
import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import java.io.IOException;

public class MainActivity extends AppCompatActivity {


private ImageView s_img;
private Button g_btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
g_btn=findViewById(R.id.button);
s_img=findViewById(R.id.imageView);
g_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(Intent.ACTION_PICK,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
activityResultLauncher.launch(intent);
}
});
}

ActivityResultLauncher<Intent>activityResultLauncher=registerForActivityResult(ne
w ActivityResultContracts.StartActivityForResult(), new
ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult activityResult) {
if (activityResult.getResultCode()== Activity.RESULT_OK) {
Intent intent = activityResult.getData();
Uri uri = intent.getData();
try {

s_img.setImageBitmap(MediaStore.Images.Media.getBitmap(getContentResolver(),
uri));
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
Toast.makeText(MainActivity.this,"Error",Toast.LENGTH_LONG).show();
}
}
});
}
OUTPUT
Practical-12
Create an application to perform the operations of create, insert, delete, view and
update, using sqlite database.
Name: Tushar Tikia Roll no: 02590302022 Sem: VI Course: BCA

Project Struture

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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textStyle="bold"
android:textSize="30sp"
android:text="Student Details" />

<EditText
android:id="@+id/editTextText"
android:layout_width="match_parent"
android:layout_height="62dp"
android:ems="10"
android:inputType="text"
android:hint="Roll No" />

<EditText
android:id="@+id/editTextText2"
android:layout_width="match_parent"
android:layout_height="64dp"
android:ems="10"
android:inputType="text"
android:hint="Student Name" />

<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="INSERT" />

<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="View" />

<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="UPDATE" />

<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="DELETE" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textSize="20sp"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/data_inserted"/>

<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:stretchColumns="1">
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="Roll No"
android:background="@color/design_default_color_primary"
android:textColor="@color/white"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/roll_txt"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="Name"
android:background="@color/design_default_color_primary"
android:textColor="@color/white"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/name_txt"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/roll_s1"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/name_s1"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/roll_s2"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/name_s2"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/roll_s3"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/name_s3"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/roll_s4"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/name_s4"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/roll_s5"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/name_s5"/>
</TableRow>
</TableLayout>
</LinearLayout>
Student_Model.java

package com.example.sqlitedemo;

public class Student_Model {


String roll_no;
String name;

public Student_Model() {
}

public Student_Model(String roll_no, String name) {


this.roll_no = roll_no;
this.name = name;
}
public String getRoll_no() {
return roll_no;
}

public void setRoll_no(String roll_no) {


this.roll_no = roll_no;
}

public String getName() {


return name;
}

public void setName(String name) {


this.name = name;
}
}
StudentDataHalper.java

package com.example.sqlitedemo;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.Nullable;

public class StudentDataHalper extends SQLiteOpenHelper {

private static final int DATABASE_VERSION = 1;


private static final String DATABASE_NAME = "studentsManager";
private static final String TABLE_CONTACTS = "students";
private static final String Roll_NO = "Roll_NO";
private static final String Student_NAME = "Name";

public StudentDataHalper(@Nullable Context context) {


super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_STUDENTS_TABLE = "CREATE TABLE " +
TABLE_CONTACTS + "("
+ Roll_NO + " INTEGER PRIMARY KEY," + Student_NAME + "
TEXT"+")";
db.execSQL(CREATE_STUDENTS_TABLE);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACTS);

// Create tables again


onCreate(db);
}

public long insertStudent(Student_Model model)


{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(Roll_NO,model.getRoll_no());
values.put(Student_NAME,model.getName());
long l=db.insert(TABLE_CONTACTS,null,values);
db.close();
return l;
}
public Student_Model fetchStudent(String roll_NO)
{
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_CONTACTS, new String[] { Roll_NO,
Student_NAME}, Roll_NO + "=?",
new String[] { roll_NO }, null, null, null, null);
if (cursor != null)
cursor.moveToFirst();

Student_Model studentModel = new


Student_Model(cursor.getString(0),cursor.getString(1));

return studentModel;
}
public List<Student_Model> fetchAllstudent()
{
List<Student_Model> modelList = new ArrayList<Student_Model>();
// Select All Query
String selectQuery = "SELECT * FROM " + TABLE_CONTACTS;

SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);

// looping through all rows and adding to list


if (cursor.moveToFirst()) {
do {
Student_Model contact = new Student_Model();
contact.setRoll_no(cursor.getString(0));
contact.setName(cursor.getString(1));
// Adding contact to list
modelList.add(contact);
} while (cursor.moveToNext());
}
// return contact list
return modelList;
}
public int updateStudent(Student_Model model)
{
SQLiteDatabase db = this.getWritableDatabase();

ContentValues values = new ContentValues();


values.put(Student_NAME,model.getName());

// updating row
return db.update(TABLE_CONTACTS, values, Roll_NO + " = ?",
new String[] { model.getRoll_no() });
}
public int deleteStudent(Student_Model model) {
SQLiteDatabase db = this.getWritableDatabase();
int r=db.delete(TABLE_CONTACTS, Roll_NO + " = ?",
new String[] { model.getRoll_no()});
db.close();
return r;
}

}
MainActivity.java

package com.example.sqlitedemo;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;
public class MainActivity extends AppCompatActivity {
StudentDataHalper sD;
EditText roll;
EditText name;
Button insert_btn,view_btn,update_btn,delete_btn;
TextView
inserted,S_roll_no,S_name,roll_s1,roll_s2,roll_s3,roll_s4,roll_s5,name_s1,name_s2,nam
e_s3,name_s4,name_s5;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
roll=findViewById(R.id.editTextText);
name=findViewById(R.id.editTextText2);
insert_btn=findViewById(R.id.button);
view_btn=findViewById(R.id.button2);
update_btn=findViewById(R.id.button3);
delete_btn=findViewById(R.id.button4);
inserted=findViewById(R.id.data_inserted);
S_roll_no=findViewById(R.id.roll_txt);
S_name=findViewById(R.id.name_txt);
roll_s1=findViewById(R.id.roll_s1);
name_s1=findViewById(R.id.name_s1);
roll_s2=findViewById(R.id.roll_s2);
name_s2=findViewById(R.id.name_s2);
roll_s3=findViewById(R.id.roll_s3);
name_s3=findViewById(R.id.name_s3);
roll_s4=findViewById(R.id.roll_s4);
name_s4=findViewById(R.id.name_s4);
roll_s5=findViewById(R.id.roll_s5);
name_s5=findViewById(R.id.name_s5);
sD=new StudentDataHalper(this);
insert_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String rll=roll.getText().toString();
String nm=name.getText().toString();
long l=sD.insertStudent(new Student_Model(rll,nm));
inserted.setText("");
if(l!=0){
inserted.setText("Inserted");
}
else {
inserted.setText("Not Inserted");
}
}
});
view_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//String rll=roll.getText().toString();
// Student_Model model=sD.fetchStudent(rll);
//String student_roll=model.getRoll_no();
//String student_name=model.getName();
List<Student_Model> modelAll=sD.fetchAllstudent();
roll_s1.setText(modelAll.get(0).getRoll_no());
name_s1.setText(modelAll.get(0).getName());
roll_s2.setText(modelAll.get(1).getRoll_no());
name_s2.setText(modelAll.get(1).getName());
roll_s3.setText(modelAll.get(2).getRoll_no());
name_s3.setText(modelAll.get(2).getName());
roll_s4.setText(modelAll.get(3).getRoll_no());
name_s4.setText(modelAll.get(3).getName());
roll_s5.setText(modelAll.get(4).getRoll_no());
name_s5.setText(modelAll.get(4).getName());
}
});
update_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String rll=roll.getText().toString();
String nm=name.getText().toString();
int l=sD.updateStudent(new Student_Model(rll,nm));
inserted.setText("");
if(l!=0){
inserted.setText("Updated");
}
else {
inserted.setText("Not Updated");
}
}
});
delete_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String rll=roll.getText().toString();
String nm=name.getText().toString();
int r =sD.deleteStudent(new Student_Model(rll,nm));
inserted.setText("");
if(r!=0){
inserted.setText("Deleted");
}
else {
inserted.setText("Not Deleted");
}
}
});
}
}
OUTPUT
CREATE TABLE INSERT DATA

View Data Update Data


Delete Data
Practical-13
Read phonebook contacts using content providers and display in list.
Name: Tushar Tikia Roll no: 02590302022 Sem: VI Course: BCA

Project Structure

Manifest.xml

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.WireLessdebugging"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

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:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
tools:context=".MainActivity">
<ListView
android:id = "@+id/list_contect"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize = "30sp"
android:text="Click"/>
</LinearLayout>

MainActivity.java

package com.example.wirelessdebugging;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.content.ContentResolver;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

public static final int REQUEST_READ_CONTACTS = 79;


ListView list;
ArrayList mobileArray;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (ActivityCompat.checkSelfPermission(this,
android.Manifest.permission.READ_CONTACTS)
== PackageManager.PERMISSION_GRANTED) {
mobileArray = getAllContacts();
} else {
requestPermission();
}
list = findViewById(R.id.list_contect);
ArrayAdapter adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, mobileArray);
list.setAdapter(adapter);
}
private void requestPermission() {
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
android.Manifest.permission.READ_CONTACTS)) {
// show UI part if you want here to show some rationale !!!
} else {
ActivityCompat.requestPermissions(this, new
String[]{android.Manifest.permission.READ_CONTACTS},
REQUEST_READ_CONTACTS);
}
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
android.Manifest.permission.READ_CONTACTS)) {
} else {
ActivityCompat.requestPermissions(this, new
String[]{android.Manifest.permission.READ_CONTACTS},
REQUEST_READ_CONTACTS);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[]
grantResults) {
switch (requestCode) {
case REQUEST_READ_CONTACTS: {
if (grantResults.length > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
mobileArray = getAllContacts();
} else {
// permission denied,Disable the
// functionality that depends on this permission.
}
return;
}
}
}
private ArrayList getAllContacts() {
ArrayList<String> nameList = new ArrayList<>();
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
String id =
cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
String name =
cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
nameList.add(name);
if (cur.getInt(cur.getColumnIndex(
ContactsContract.Contacts.HAS_PHONE_NUMBER)) > 0) {
Cursor pCur = cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
new String[]{id}, null);
while (pCur.moveToNext()) {
String phoneNo =
pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.N
UMBER));
}
pCur.close();
}
}
}
return nameList;
}
}
OUTPUT
Practical-14
Create an application that uses checkbox for construction of a shopping list so the
user can check off items as they are picked up. The checked items should be
displayed in a textview control.
Name: Tushar Tikia Roll no: 02590302022 Sem: VI Course: BCA

Project Structure

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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/item_textview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sopping Items"
android:gravity="center"
android:textSize="20sp"
android:textStyle="bold"/>
<ListView
android:id="@+id/item_list"
android:layout_width="match_parent"
android:layout_height="451dp" />
<LinearLayout
android:id="@+id/items"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/item_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Selected Items"
android:gravity="center"
android:textSize="20sp"
android:textStyle="bold"/>
<ListView
android:gravity="center"
android:id="@+id/select_item_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>

Item_row.xml

<?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="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="10dp"
android:padding="10dp">

<CheckBox
android:id="@+id/check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

</LinearLayout>
</LinearLayout>

Verson.java

package com.example.shoppinglist;

public class Versons {


public String version;
boolean isSelected = true;

public Versons(String version) {


this.version = version;
}

public Versons() {
}

public String getVersion() {


return version;
}

public void setVersion(String version) {


this.version = version;
}

public boolean isSelected() {


return isSelected;
}

public void setSelected(boolean selected) {


isSelected = selected;
}
}
VersonsAdapter.java

package com.example.shoppinglist;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class VersonsAdapter extends ArrayAdapter<Versons> {


Context context;
List<Versons> list = new ArrayList<>();
public VersonsAdapter(@NonNull Context context, int resource, @NonNull
List<Versons> list) {
super(context, resource, list);
this.context = context;
this.list = list;
list.addAll(list);
}

@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull
ViewGroup parent) {

VersonHolder holder = new VersonHolder();

if (convertView == null){

LayoutInflater inflater = (LayoutInflater)


context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.item_row,null);

holder.checkBox = convertView.findViewById(R.id.check_box);
holder.textView = convertView.findViewById(R.id.tv_name);
holder.checkBox.setOnCheckedChangeListener((MainActivity)context);

convertView.setTag(holder);

}else{
holder = (VersonHolder) convertView.getTag();
}

Versons versions = list.get(position);


holder.textView.setText(versions.getVersion());
holder.checkBox.setTag(list);

return convertView;
}
public static class VersonHolder{
public CheckBox checkBox;
public TextView textView;
}
}
MainActivity.java

package com.example.shoppinglist;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements


CompoundButton.OnCheckedChangeListener {

ListView listView;
ListView Select_listView;
List<Versons> list;
List<String> Select_list;
TextView select_item;
VersonsAdapter versonsAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = findViewById(R.id.item_list);
Select_listView = findViewById(R.id.select_item_list);
select_item=findViewById(R.id.item_textview);
list = new ArrayList<>();
Select_list = new ArrayList<>();
list.add(new Versons("Mirch"));
list.add(new Versons("Moog Daal"));
list.add(new Versons("Sugar"));
list.add(new Versons("Salt"));
list.add(new Versons("Eclair"));
list.add(new Versons("Honey"));
list.add(new Versons("GingerBread"));
list.add(new Versons("Kachori"));
list.add(new Versons("IceCream"));
list.add(new Versons("Jelly"));
list.add(new Versons("Kitkat"));
list.add(new Versons("Lolipop"));
list.add(new Versons("Milk"));
list.add(new Versons("Tea"));
list.add(new Versons("Oreo"));
versonsAdapter = new VersonsAdapter(MainActivity.this,R.layout.item_row,list);
listView.setAdapter(versonsAdapter);
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
int position = listView.getPositionForView(buttonView);
if (position != ListView.INVALID_POSITION){
Versons versions = list.get(position);
versions.setSelected(isChecked);
String items=versions.getVersion();
Select_list.add(items);
}
ArrayAdapter<String> slect=new ArrayAdapter(MainActivity.this,
androidx.appcompat.R.layout.support_simple_spinner_dropdown_item,Select_list);
Select_listView.setAdapter(slect);
}
}
OUTPUT
Practical-15
Create an application to take picture using native application.
Name: Tushar Tikia Roll no: 02590302022 Sem: VI Course: BCA

Project Structure

AndroidManifest.xml

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-feature android:name="android.permission.CAMERA"/>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.NativApplication"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
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:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Picture"
android:textSize="15sp"
android:id="@+id/btn"/>
</LinearLayout>

MainActivity.java

package com.example.nativapplication;

import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
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;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

Button IMAGE;
ImageView view;
ActivityResultLauncher<Intent> mStartForResult = registerForActivityResult(new
ActivityResultContracts.StartActivityForResult(),
new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {

Toast.makeText(getApplicationContext(),result.toString(),Toast.LENGTH_LONG).sho
w();
if (result.getResultCode() == Activity.RESULT_OK) {
Intent intent = result.getData();
Bundle data=intent.getExtras();
Bitmap bitmap= (Bitmap) data.get("data");
view.setImageBitmap(bitmap);
}
}
});
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
IMAGE=findViewById(R.id.btn);
view=findViewById(R.id.imageview);
IMAGE.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mStartForResult.launch(intent);
}
});
}
}
OUTPUT
MYAPP NATIVEAPP

You might also like