Ayush Negi
Ayush Negi
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’.
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.
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:
<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
OUTPUT:
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
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
@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
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;
@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;
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;
@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
}
});
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)
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;
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">
<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" />
<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>
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;
@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 ");
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">
<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" />
</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;
@Override
public void onCreate(SQLiteDatabase db) {
@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);
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;
@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);
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();
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;
@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);
}
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;
@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);
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();
OUTPUT:
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
PRACTICAL 9:
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;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMapsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
OUTPUT:
NAME: Ayush Negi CLASS ROLL NO: 20
COURSE: MCA-3(F) UNIVERSITY ROLL NO: - 2301104
PRACTICAL 10:
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;
@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();
}
});
}
@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:
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;
@Override
public void onCreate(SQLiteDatabase db) {
String createTableQuery = "CREATE TABLE " + TABLE_USERS + "("
+ COL_USERNAME + " TEXT PRIMARY KEY, "
+ COL_PASSWORD + " TEXT)";
db.execSQL(createTableQuery);
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{ db.execSQL("DROP TABLE IF EXISTS " + TABLE_USERS);
onCreate(db);
}
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
@Override
public void onCreate(SQLiteDatabase db) {
String createTableQuery = "CREATE TABLE " + TABLE_USERS + "("
+ COL_USERNAME + " TEXT PRIMARY KEY, "
+ COL_PASSWORD + " TEXT)";
db.execSQL(createTableQuery);
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{ db.execSQL("DROP TABLE IF EXISTS " + TABLE_USERS);
onCreate(db);
}
OUTPUT: