0% found this document useful (0 votes)
19 views68 pages

Ayush Negi

The document outlines practical exercises for an Android application development course, detailing steps to install Android Studio and create various applications. It includes code snippets for XML layouts and Java classes for applications that display messages, utilize Toast notifications, and implement a simple calculator. Each practical exercise is accompanied by specific XML and Java code examples to guide the development process.

Uploaded by

Sachin Rana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views68 pages

Ayush Negi

The document outlines practical exercises for an Android application development course, detailing steps to install Android Studio and create various applications. It includes code snippets for XML layouts and Java classes for applications that display messages, utilize Toast notifications, and implement a simple calculator. Each practical exercise is accompanied by specific XML and Java code examples to guide the development process.

Uploaded by

Sachin Rana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 68

NAME: Ayush Negi CLASS ROLL NO: 20

COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

PRACTICAL 1:
Write down the steps to set up Android Studio.
Steps to Install Android Studio on Windows
Step 1: Go to https://developer.android.com website.
Step 2: Click on the Download Android Studio Button.

Click on the “I have read and agree with the above terms and conditions” checkbox followed by
the download button.

Click on the Save file button in the appeared prompt box and the file will start downloading.
Step 3: After the downloading has finished, open the file from downloads and run it. It will
prompt the following dialog box.
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

Click on next. In the next prompt, it’ll ask for a path for installation. Choose a path and hit next.
Step 4: It will start the installation, and once it is completed, it will be like the image shown
below.

Click on next.
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

Step 5: Once ” Finish ” is clicked, it will ask whether the previous settings need to be imported
[if the android studio had been installed
earlier], or not. It is better to choose the ‘Don’t import Settings option’.

Click the OK button.


Step 6: This will start the Android Studio.
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

Meanwhile, it will be finding the available SDK components.

Step 7: After it has found the SDK components, it will redirect to the Welcome dialog box.

Click on Next .
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
Choose Standard and click on Next. Now choose the theme, whether the Light theme or the
Dark one. The light one is called the IntelliJ theme whereas the dark theme is
called Dracula . Choose as required.

Click on the Next button.

Step 8: Now it is time to download the SDK components.

Click on Finish. Components begin to download let it complete.


NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

The Android Studio has been successfully configured. Now it’s time to launch and build
apps. Click on the Finish button to launch it.
Step 9: Click on Start a new Android Studio project to build a new app.
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

PRACTICAL 2:
A. Create an Android application that displays the message “Welcome to
Graphic Era University - MCA” at the click of a button.

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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="410dp"
android:layout_height="134dp"
android:text="Welcome to Graphic Era Hill University MCA - Batch 2023-2025"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.476"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

JAVA:
package com.example.printtext; import android.os.Bundle;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity; import
androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class MainActivity extends AppCompatActivity
{
@Override

protected void onCreate(Bundle savedInstanceState)


{ super.onCreate(savedInstanceState); EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v,
insets) -> {
Insets
systemBars=insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right,
systemBars.bottom); return insets;
});
}
}
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

OUTPUT:
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

B. Create an Android application that displays the message “Welcome


to Graphic Era University - MCA” at the click of a button.

XML:

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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="267dp"
android:layout_height="45dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.567"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button"
app:layout_constraintVertical_bias="0.076" />

<Button
android:id="@+id/button"
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
android:layout_width="176dp"
android:layout_height="54dp"
android:text="Click for message"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.536"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.525" />

</androidx.constraintlayout.widget.ConstraintLayout>

JAVA:

MainActivity.java
package com.example.myapplication;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

public class MainActivity extends AppCompatActivity


{ Button b;
TextView t;

@Override
protected void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
b=findViewById(R.id.button);
t=findViewById(R.id.textView);

b.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {
t.setText("Welcome to Graphic Era University- MCA BATCH 2023-2025");
}
});
// b.setOnClickListener(v -> t.setText("Welcome to Android"));
}
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

OUTPUT:
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

C. Create an Android application to display the message “Welcome to GEHU


- learning Android Application Development - MCA” and execute the
application using different emulators.

XML:

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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="267dp"
android:layout_height="45dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.567"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button"
app:layout_constraintVertical_bias="0.076" />

<Button
android:id="@+id/button"
android:layout_width="176dp"
android:layout_height="54dp"
android:text="Click for message"
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.536"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.525" />

</androidx.constraintlayout.widget.ConstraintLayout>

JAVA:
MainActivity.java
package com.example.myapplication;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity


{ Button b;
TextView t;

@Override
protected void onCreate(Bundle savedInstanceState) {
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) ->
{
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right,
systemBars.bottom);
return insets;
});
b=findViewById(R.id.button);
t=findViewById(R.id.textView);

b.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {
t.setText("Welcome to Graphic Era University- MCA BATCH 2023-2025");
}
});
// b.setOnClickListener(v -> t.setText("Welcome to Android"));
}
}
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

OUTPUT:
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

PRACTICAL 3:
Illustrate with a suitable example the use of Toast to display a message in
an Android application. {The message display should wait for a long
time]

XML :
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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
android:id="@+id/button"
android:layout_width="230dp"
android:layout_height="61dp"
android:text="Click on the button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.499" />
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

</androidx.constraintlayout.widget.ConstraintLayout>

JAVA:
MainActivity.java
package com.example.toast;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

Button b;
@Override
protected void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) ->
{
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right,
systemBars.bottom);
return insets;
});

b=findViewById( R.id.button);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Toast.makeText(MainActivity.this, "Button
Clicked", Toast.LENGTH_LONG).show();
}
});
}
}
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

OUTPUT:
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

PRACTICAL 4:
Create an Android application for designing a simple calculator having
basic functionality like Addition, Subtraction, Multiplication, and
Division using controls like Buttons, Text Views, Edit Texts, etc.
XML :
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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/resultTextView"
android:layout_width="406dp"
android:layout_height="143dp"
android:text="0"
android:textAlignment="center"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />

<Button
android:id="@+id/button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.625"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.293" />

<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.306"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
app:layout_constraintVertical_bias="0.427" />

<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/buttonMultiply"
app:layout_constraintHorizontal_bias="0.603"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.427" />

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.021"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.558" />
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

<Button
android:id="@+id/button0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.306"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.69" />

<Button
android:id="@+id/buttonClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.012"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.692" />
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
<Button
android:id="@+id/buttonAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.291" />

<Button
android:id="@+id/buttonSubtract"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.427" />

<Button
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
android:id="@+id/buttonMultiply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="*"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.554" />

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.594"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.553" />

<Button
android:id="@+id/button4"
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="@+id/buttonClear"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.021"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.618" />

<Button
android:id="@+id/buttonDivide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.691" />

<Button
android:id="@+id/buttonEquals"
android:layout_width="wrap_content"
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
android:layout_height="wrap_content"
android:text="="
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.603"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.69" />

<Button
android:id="@+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.021"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.297" />

<Button
android:id="@+id/button8"
android:layout_width="96dp"
android:layout_height="51dp"
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
android:text="8"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.313"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.295" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.306"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.558" />
</androidx.constraintlayout.widget.ConstraintLayout>

JAVA:
MainActivity.java
package com.example.calculator;
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
import android.annotation.SuppressLint;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity


{ TextView resultTextView;
double firstOperand = 0;
double secondOperand = 0;
String operator = "";
Button b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15;

@SuppressLint("MissingInflatedId"
) @Override
protected void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
// EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
resultTextView =
findViewById(R.id.resultTextView);
// Set click listeners for number buttons
b0=findViewById(R.id.button7);
b1=findViewById(R.id.button8);
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
b2=findViewById(R.id.button9)
;
b3=findViewById(R.id.button4)
;
b4=findViewById(R.id.button5)
;
b5=findViewById(R.id.button6)
;
b6=findViewById(R.id.button1)
;
b7=findViewById(R.id.button2)
;
b8=findViewById(R.id.button3)
;
b9=findViewById(R.id.button0)
;
b10=findViewById(R.id.buttonAdd);
b11=findViewById(R.id.buttonSubtract);
b12=findViewById(R.id.buttonMultiply);
b13=findViewById(R.id.buttonDivide);
b14=findViewById(R.id.buttonClear);
b15=findViewById(R.id.buttonEquals);

b0.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {

}
});
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
b1.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {

}
});

b2.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {

}
});

b3.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {

}
});

b4.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {

}
});

b5.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

}
});

b6.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {

}
});

b7.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {

}
});

b8.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {

}
});

b9.setOnClickListener(new View.OnClickListener()
{ @Override
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

public void onClick(View v) {

}
});

b10.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {

}
});

b11.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {

}
});

b12.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {

}
});

b13.setOnClickListener(new View.OnClickListener() {
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

@Override
public void onClick(View v) {

}
});

b14.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {

}
});

b15.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {

}
});

setNumberButtonClickListener(R.id.button0, "0");
setNumberButtonClickListener(R.id.button1, "1");
setNumberButtonClickListener(R.id.button2, "2");
setNumberButtonClickListener(R.id.button3, "3");
setNumberButtonClickListener(R.id.button4, "4");
setNumberButtonClickListener(R.id.button5, "5");
setNumberButtonClickListener(R.id.button6, "6");
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

setNumberButtonClickListener(R.id.button7, "7");
setNumberButtonClickListener(R.id.button8, "8");
setNumberButtonClickListener(R.id.button9, "9");
// ... (Add for buttons 3 to 9)

// Set click listeners for operator buttons


setOperatorButtonClickListener(R.id.buttonAdd, "+");
setOperatorButtonClickListener(R.id.buttonSubtract, "-");
setOperatorButtonClickListener(R.id.buttonMultiply, "*");
setOperatorButtonClickListener(R.id.buttonDivide, "/");

// Set click listener for equals button


findViewById(R.id.buttonEquals).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{ calculateResult();
}
});

// Set click listener for clear button


findViewById(R.id.buttonClear).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view)
{ clearCalculator();
}
});
}
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

private void setNumberButtonClickListener(int buttonId, final String number)


{ findViewById(buttonId).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String currentText = resultTextView.getText().toString();
if (currentText.equals("0")) {
resultTextView.setText(number);
} else {
resultTextView.setText(currentText + number);
}
}
});
}
private void setOperatorButtonClickListener(int buttonId, final String operator)
{ findViewById(buttonId).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MainActivity.this.operator = operator;
firstOperand = Double.parseDouble(resultTextView.getText().toString());
resultTextView.setText("0"); // Reset for second operand input
}
});
}
private void calculateResult() {
secondOperand = Double.parseDouble(resultTextView.getText().toString());
double result = 0;
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

switch (operator) {
case "+":
result = firstOperand + secondOperand;
break;
case "-":
result = firstOperand - secondOperand;
break;
case "*":
result = firstOperand * secondOperand;
break;
case "/":
if (secondOperand != 0) {
result = firstOperand / secondOperand;
} else {
resultTextView.setText("Error");
return; // Avoid displaying result in case of division by zero
}
break;
}
resultTextView.setText(String.valueOf(result));
}
private void clearCalculator() {
firstOperand = 0;
secondOperand = 0;
operator = "";
resultTextView.setText("0");
}}
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

OUTPUT:
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

PRACTICAL 5:
Illustrate with a suitable example the use of Intents in linking activities.
At least 2 activities are to be used.
Illustrate with a suitable example the use of Intents in navigating to any
other website. [navigate to Graphic Era University Website]

XML :

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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
android:id="@+id/openWebButton"
android:layout_width="190dp"
android:layout_height="55dp"
android:text="Open application"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

JAVA:

MainActivity.java
package com.example.internalintent;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
import android.view.View;
import android.widget.Button;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity


{ Button b;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) ->
{ Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});

b=findViewById(R.id.openWebButton);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = "https://www.gehu.ac.in";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}
});

}
}
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

OUTPUT:
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

PRACTICAL 6:
WAA that demonstrates the use of check box and radio button widget your app
should allow user to select multi- food preferences using check boxes and chouse
their favorite drink using radio button.

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

<!-- Title -->


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Your Food Preferences"
android:textSize="18sp"
android:layout_marginBottom="10dp" />

<!-- CheckBoxes for Food Preferences -->


<CheckBox
android:id="@+id/chkPizza"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pizza" />

<CheckBox
android:id="@+id/chkBurger"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Burger" />

<CheckBox
android:id="@+id/chkPasta"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pasta" />

<!-- Separator -->


<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#cccccc"
android:layout_marginVertical="16dp" />
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
<!-- Title -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="Choose Your Favorite Drink"


android:textSize="18sp"
android:layout_marginBottom="10dp" />

<!-- RadioGroup for Drinks -->


<RadioGroup
android:id="@+id/radioGroupDrinks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<RadioButton
android:id="@+id/radioTea"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tea" />

<RadioButton
android:id="@+id/radioCoffee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Coffee" />

<RadioButton
android:id="@+id/radioJuice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Juice" />
</RadioGroup>

<!-- Submit Button -->


<Button
android:id="@+id/btnSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_marginTop="20dp" />
</LinearLayout>
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
JAVA:
package com.example.foodanddrink;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioButton;
import
android.widget.RadioGroup;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

private CheckBox chkPizza, chkBurger, chkPasta;


private RadioGroup radioGroupDrinks;
private Button btnSubmit;

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

chkPizza = findViewById(R.id.chkPizza);
chkBurger = findViewById(R.id.chkBurger);
chkPasta = findViewById(R.id.chkPasta);
radioGroupDrinks = findViewById(R.id.radioGroupDrinks);
btnSubmit = findViewById(R.id.btnSubmit);

btnSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
StringBuilder foodPreferences = new StringBuilder("Selected Food: ");
if (chkPizza.isChecked()) foodPreferences.append("Pizza ");
if (chkBurger.isChecked()) foodPreferences.append("Burger ");
if (chkPasta.isChecked()) foodPreferences.append("Pasta ");

int selectedDrinkId = radioGroupDrinks.getCheckedRadioButtonId();


String selectedDrink = "None";
if (selectedDrinkId != -1) {
RadioButton selectedRadioButton = findViewById(selectedDrinkId);
selectedDrink = selectedRadioButton.getText().toString();
}

String message = foodPreferences.toString() + "\nSelected Drink: " + selectedDrink;


Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
}
});
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
OUTPUT:
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

PRACTICAL 7:
WAA to create a and perform insertion .eg- a create DB name Student DB where the
attributes are Name Roll no Course And average marks.

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

<!-- Input Fields -->


<EditText
android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name" />

<EditText
android:id="@+id/etRollNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Roll No"
android:inputType="number" />
<EditText
android:id="@+id/etCourse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Course" />

<EditText
android:id="@+id/etAvgMarks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Average Marks"
android:inputType="numberDecimal" />

<!-- Button -->


<Button
android:id="@+id/btnInsert"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Insert Data"
android:layout_marginTop="16dp" />

</LinearLayout>
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

DBHelper.java
package com.example.studentdb;

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

public class DBHelper extends SQLiteOpenHelper {

private static final String DATABASE_NAME = "StudentDB";


private static final int DATABASE_VERSION = 1;
private static final String TABLE_NAME = "Students";

private static final String COLUMN_NAME = "Name";


private static final String COLUMN_ROLL_NO = "RollNo";
private static final String COLUMN_COURSE = "Course";
private static final String COLUMN_AVERAGE_MARKS = "AverageMarks";

public DBHelper(Context context) {


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

@Override
public void onCreate(SQLiteDatabase db) {

String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" +


COLUMN_ROLL_NO + " INTEGER PRIMARY KEY, " +
COLUMN_NAME + " TEXT, " +
COLUMN_COURSE + " TEXT, " +
COLUMN_AVERAGE_MARKS + " REAL)";
db.execSQL(CREATE_TABLE);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop the table if it exists and recreate it
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}

public boolean insertStudent(String name, int rollNo, String course, float averageMarks) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COLUMN_NAME, name);
contentValues.put(COLUMN_ROLL_NO, rollNo);
contentValues.put(COLUMN_COURSE, course);
contentValues.put(COLUMN_AVERAGE_MARKS, averageMarks);

long result = db.insert(TABLE_NAME, null, contentValues);


db.close();
return result != -1; // Return true if insert is successful
}
}
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

JAVA:
package com.example.studentdb;

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

public class MainActivity extends AppCompatActivity {

private EditText etName, etRollNo, etCourse, etAvgMarks;


private Button btnInsert;
private DBHelper dbHelper;

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

etName = findViewById(R.id.etName);
etRollNo = findViewById(R.id.etRollNo);
etCourse = findViewById(R.id.etCourse);
etAvgMarks = findViewById(R.id.etAvgMarks);
btnInsert = findViewById(R.id.btnInsert);

dbHelper = new DBHelper(this);

btnInsert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = etName.getText().toString();
String rollNo = etRollNo.getText().toString();
String course = etCourse.getText().toString();
String avgMarks = etAvgMarks.getText().toString();

if (name.isEmpty() || rollNo.isEmpty() || course.isEmpty() || avgMarks.isEmpty()) {


Toast.makeText(MainActivity.this, "Please fill all fields", Toast.LENGTH_SHORT).show();
} else {
boolean isInserted = dbHelper.insertStudent(name, Integer.parseInt(rollNo), course,
Float.parseFloat(avgMarks));
if (isInserted) {
Toast.makeText(MainActivity.this, "Data Inserted Successfully",
Toast.LENGTH_SHORT).show();
etName.setText("");
etRollNo.setText("");
etCourse.setText("");
etAvgMarks.setText("");
} else {
Toast.makeText(MainActivity.this, "Insertion Failed", Toast.LENGTH_SHORT).show();
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

OUTPUT:
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

PRACTICAL 8:

WAA to perform update when the user wants to update any field with the help of
number and delete with the help of number.

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

<EditText
android:id="@+id/editTextId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="ID"
android:inputType="number" />

<EditText
android:id="@+id/editTextName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name" />

<EditText
android:id="@+id/editTextAge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Age"
android:inputType="number" />

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

<Button
android:id="@+id/buttonDelete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Delete" />
</LinearLayout>
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
DBHelper.java:

package com.example.updateanddelete;

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

public class DatabaseHelper extends SQLiteOpenHelper


{ private static final String DATABASE_NAME =
"Records.db"; private static final String TABLE_NAME =
"records";
private static final String COL_2 = "NAME";
private static final String COL_3 = "AGE";

public DatabaseHelper(Context context)


{ super(context, DATABASE_NAME, null, 1);
}

@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_NAME + " (ID INTEGER PRIMARY KEY
AUTOINCREMENT, NAME TEXT, AGE INTEGER)");
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{ db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}

public boolean updateData(String id, String name, String age)


{ SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_2, name);
contentValues.put(COL_3, age);
int result = db.update(TABLE_NAME, contentValues, "ID = ?", new String[]{id});
return result > 0;
}

public Integer deleteData(String id)


{ SQLiteDatabase db =
this.getWritableDatabase();
return db.delete(TABLE_NAME, "ID = ?", new String[]{id});
}
}
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
JAVA:
package com.example.studentdb;

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

public class MainActivity extends AppCompatActivity {

private EditText etName, etRollNo, etCourse, etAvgMarks;


private Button btnInsert;
private DBHelper dbHelper;

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

etName = findViewById(R.id.etName);
etRollNo = findViewById(R.id.etRollNo);
etCourse = findViewById(R.id.etCourse);
etAvgMarks = findViewById(R.id.etAvgMarks);
btnInsert = findViewById(R.id.btnInsert);

dbHelper = new DBHelper(this);

btnInsert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = etName.getText().toString();
String rollNo = etRollNo.getText().toString();
String course = etCourse.getText().toString();
String avgMarks = etAvgMarks.getText().toString();

if (name.isEmpty() || rollNo.isEmpty() || course.isEmpty() || avgMarks.isEmpty())


{ Toast.makeText(MainActivity.this, "Please fill all fields", Toast.LENGTH_SHORT).show();
} else {
boolean isInserted = dbHelper.insertStudent(name, Integer.parseInt(rollNo), course,
Float.parseFloat(avgMarks));
if (isInserted) {
Toast.makeText(MainActivity.this, "Data Inserted Successfully",
Toast.LENGTH_SHORT).show();
etName.setText("");
etRollNo.setText("");
etCourse.setText("");
etAvgMarks.setText("");
} else {
Toast.makeText(MainActivity.this, "Insertion Failed", Toast.LENGTH_SHORT).show();
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

OUTPUT:
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

PRACTICAL 9:

WAA to display google map with the marker location of India.

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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity">

<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>
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
JAVA:

package com.example.mylife;

import androidx.fragment.app.FragmentActivity;

import android.os.Bundle;

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.example.mylife.databinding.ActivityMapsBinding;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback

{ private GoogleMap mMap;


private ActivityMapsBinding binding;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

binding = ActivityMapsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()


.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;

LatLng sydney = new LatLng(-34, 151);


mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

OUTPUT:
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

PRACTICAL 10:

With the help SMS manager class WAA to send SMS

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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

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

<EditText
android:id="@+id/phoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Phone Number"
android:inputType="phone" />

<EditText
android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Message"
android:inputType="text" />

<Button
android:id="@+id/sendSmsButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Send SMS" />
</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

JAVA:
package com.example.smsprgm;

import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.Manifest;

public class MainActivity extends AppCompatActivity {

private static final int SMS_PERMISSION_REQUEST_CODE = 101;

private EditText phoneNumber ;


private EditText message;
private Button sendSmsButton;

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

phoneNumber = findViewById(R.id.phoneNumber);
message = findViewById(R.id.message);
sendSmsButton = findViewById(R.id.sendSmsButton);

sendSmsButton.setOnClickListener(view -> {
if (ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.SEND_SMS)
!= PackageManager.PERMISSION_GRANTED) {
// Request SMS permission
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.SEND_SMS},
SMS_PERMISSION_REQUEST_CODE);
} else {
// Permission already granted, send SMS
sendSms();
}
});
}

private void sendSms() {


NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
String phone = phoneNumber.getText().toString().trim();
String textMessage = message.getText().toString().trim();

if (!phone.isEmpty() && !textMessage.isEmpty())


{ try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phone, null, textMessage, null, null);
Toast.makeText(this, "SMS Sent Successfully!", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(this, "SMS Sending Failed: " + e.getMessage(),
Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(this, "Please enter both phone number and message",
Toast.LENGTH_SHORT).show();
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == SMS_PERMISSION_REQUEST_CODE) {
if (grantResults.length > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
sendSms();
} else {
Toast.makeText(this, "SMS Permission Denied", Toast.LENGTH_SHORT).show();
}
}
}
}
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
OUTPUT:
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

PRACTICAL 11:
State the step-by-step procedure to publish an app on play store.

Publishing an app on the **Google Play Store** requires a structured process, starting from
preparing your app to setting up a Play Console account and submitting your app. Here is the
step- by-step guide:

Step 1: Prepare Your App for Release


1. Completion of Development:
- The app should be complete, functional, and thoroughly tested.
- Crash rate, bugs, and performance issues should be at minimum rates.

2. Build a Signed APK or App Bundle:


- In Android Studio:
1. Go to Build > Generate Signed Bundle /APK.
2. Choose Android App Bundle (preferable) or APK
3. Create a Keystore (if you do not already have one). This will be used in order to sign your app.

Step 2: Set Up a Google Play Developer Account


1. Go to the [Google Play Console](https://play.google.com/console/).
2. Sign in using your Google account.
3. Pay a one-time registration fee.
4. Fill in the details for account setup using your developer name and email.

Step 3: Prepare the Store Listing


1. Go to Play Console and then select Create App.
2. Fill in your store listing details
a. App Title: Name of your app
b. Short Description: Brief description of your app
c. Full Description: Explanation of app's features
d. Graphics Upload for assets:
App icon-512 x 512 px, PNG.
- Cover art (1024 x 500 px, JPG or PNG).
- Screenshots of the app on various screen sizes.
Category: Select a category (e.g. Game, Education, etc.).

Step 4: Content Setup of App


1. Go to the App Content section in your Play Console.
2. For each form, provide whatever is needed
- URL of Privacy Policy: Provide a link to your privacy policy (hosted on a website).
- Ads Declaration: Specify if your app contains any advertisements.
- Content Rating: Fill out the questionnaire to determine the rating of the app.
- Target Audience and Content: Specify what age group the app is targeting.
- Data Safety: State how your app deals with user data.

Step 5: Pricing and Distribution


NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
1. Go to the Pricing & Distribution section:
- Select if your app is Free or Paid.
- Choose countries/regions that you want your application to be distributed in.
- Review that your application is ready to be included in Android TV or Wear OS.

Step 6: Upload Your App


1. Step to Production > Create Release**.
2. Upload your App Bundle (.aab) or APK (.apk).
3. Include release notes for the app version (for instance, what is new and what issues
were fixedStep 7: Final Review and Publish**
1. Make sure all areas in the Play Console are complete:
- Store Listing.
- App Content.
- Pricing & Distribution.
- App Release.
2. To submit your app for review, click Publish.

Step 8: Wait for Google’s Review


1. Google will review your app to ensure it meets Play Store policies.
2. This process typically takes a few hours to a couple of days.
3. You will be notified via email once the app is approved.
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104

PRACTICAL 12:
Write an android app. To perform login, where it will take place by authenticating
the credentials from the DB.

XML:

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

<EditText
android:id="@+id/etUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username" />

<EditText
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword" />

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

</LinearLayout>
NAME: Divya CLASS ROLL NO: 23
COURSE: MCA-3(E) UNIVERSITY ROLL NO: - 2301136
DBHelper.java:
package com.example.myapplication;

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

public class DBHelper extends SQLiteOpenHelper {

private static final String DATABASE_NAME = "UserDB.db";


private static final int DATABASE_VERSION = 1;
private static final String TABLE_USERS = "users";
private static final String COL_USERNAME = "username";
private static final String COL_PASSWORD = "password";

public DBHelper(Context context) {


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

@Override
public void onCreate(SQLiteDatabase db) {
String createTableQuery = "CREATE TABLE " + TABLE_USERS + "("
+ COL_USERNAME + " TEXT PRIMARY KEY, "
+ COL_PASSWORD + " TEXT)";
db.execSQL(createTableQuery);

ContentValues values = new ContentValues();


values.put(COL_USERNAME, "testuser");
values.put(COL_PASSWORD, "1234");
db.insert(TABLE_USERS, null, values);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{ db.execSQL("DROP TABLE IF EXISTS " + TABLE_USERS);
onCreate(db);
}

public boolean authenticateUser(String username, String password)


{ SQLiteDatabase db = this.getReadableDatabase();
String query = "SELECT * FROM " + TABLE_USERS + " WHERE " + COL_USERNAME +
"=? AND " + COL_PASSWORD + "=?";
Cursor cursor = db.rawQuery(query, new String[]{username, password});
boolean isAuthenticated = cursor.getCount() > 0;
cursor.close();
db.close();
return isAuthenticated;
NAME: Divya CLASS ROLL NO: 23
COURSE: MCA-3(E) UNIVERSITY ROLL NO: - 2301136
JAVA:
package com.example.myapplication;

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

public class DBHelper extends SQLiteOpenHelper {

private static final String DATABASE_NAME = "UserDB.db";


private static final int DATABASE_VERSION = 1;
private static final String TABLE_USERS = "users";
private static final String COL_USERNAME = "username";
private static final String COL_PASSWORD = "password";

public DBHelper(Context context) {


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

@Override
public void onCreate(SQLiteDatabase db) {
String createTableQuery = "CREATE TABLE " + TABLE_USERS + "("
+ COL_USERNAME + " TEXT PRIMARY KEY, "
+ COL_PASSWORD + " TEXT)";
db.execSQL(createTableQuery);

ContentValues values = new ContentValues();


values.put(COL_USERNAME, "testuser");
values.put(COL_PASSWORD, "1234");
db.insert(TABLE_USERS, null, values);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{ db.execSQL("DROP TABLE IF EXISTS " + TABLE_USERS);
onCreate(db);
}

public boolean authenticateUser(String username, String password)


{ SQLiteDatabase db = this.getReadableDatabase();
String query = "SELECT * FROM " + TABLE_USERS + " WHERE " + COL_USERNAME +
"=? AND " + COL_PASSWORD + "=?";
Cursor cursor = db.rawQuery(query, new String[]{username, password});
boolean isAuthenticated = cursor.getCount() > 0;
cursor.close();
db.close();
return isAuthenticated;
NAME: Divya CLASS ROLL NO: 23
COURSE: MCA-3(E) UNIVERSITY ROLL NO: - 2301136

OUTPUT:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy