AndroidFinal AK
AndroidFinal AK
Steps:
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.
1
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
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.
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.
2
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
Step 7: After it has found the SDK components, it will redirect to the Welcome dialog box.
Click on Next .
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.
Step 9: Click on Start a new Android Studio project to build a new app.
3
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
4
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
Que2(A): Create an Android application that displays the message “Welcome to Graphic Era
University - MCA” at the click of a button.
Code:
XML
<TextView android:id="@+id/textView"
android:layout_width="292dp" android:layout_height="79dp"
android:textAlignment="center"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent "
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.144" />
<Button android:id="@+id/button"
android:layout_width="148dp"
android:layout_height="69dp"
android:layout_marginTop="12dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:layout_constraintVertical_bias="0.251" />
</androidx.constraintlayout.widget.ConstraintLayout>
JAVA
package com.example.practical1;
5
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
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;
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;
});
btn = findViewById(R.id.button);
txt = findViewById(R.id.textView);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
txt.setText("Welcome to Graphic Era University - MCA"); }
});
}
}
6
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
OUTPUT:
7
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
Que2(B): Create an Android application to display the message “Welcome to GEHU learning
Android Application Development - MCA” and execute the application using different emulators.
Code:
XML
android:layout_height="match_parent" tools:context=".MainActivity">
<TextView android:id="@+id/textView"
android:layout_width="292dp" android:layout_height="79dp"
android:textAlignment="center" android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent "
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.144" />
<Button android:id="@+id/button"
android:layout_width="148dp"
android:layout_height="69dp"
android:layout_marginTop="12dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:layout_constraintVertical_bias="0.251" />
</androidx.constraintlayout.widget.ConstraintLayout>
JAVA
package com.example.practical1;
8
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
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;
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
txt.setText("Welcome to GEHU - learning Android Application Development
MCA");
}
});
}
}
9
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
OUTPUT:
10
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
Que3: 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} Code:
Code:
XML
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" android:textSize="20sp"
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
package com.example.practical2;
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 {
11
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
Button button ;
@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;
});
button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this,"Button Clicked",Toast.LENGTH_LONG).show();
}
});
}
}
12
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
OUTPUT:
13
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
Que4: 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.
Code:
XML
<EditText android:id="@+id/edt1"
android:layout_width="403dp"
android:layout_height="63dp"
android:ems="10"
android:hint="Enter Num 1"
android:inputType="number"
android:textAlignment="textEnd"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/result"
app:layout_constraintVertical_bias="0.1" />
<TextView android:id="@+id/result"
android:layout_width="348dp"
android:layout_height="76dp"
android:textAlignment="center"
android:textSize="34sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
14
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
app:layout_constraintHorizontal_bias="0.492"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.338" />
<EditText android:id="@+id/edt2"
android:layout_width="403dp"
android:layout_height="65dp"
android:ems="10"
android:hint="Enter Num 2"
android:inputType="number"
android:textAlignment="textEnd "
android:textSize="20sp"
app:layout_constraintBottom_to
BottomOf="parent"
app:layout_constraintEnd_toEnd Of="parent"
app:layout_constraintHorizontal _bias="0.497"
app:layout_constraintStart_toSta rtOf="parent"
app:layout_constraintTop_toBott omOf="@+id/edt1"
<GridLayout android:id="@+id/gridLayout"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:columnCount="4" android:rowCount="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edt2"
app:layout_constraintVertical_bias="0.25">
<Button android:id="@+id/btnplus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
15
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
android:layout_column="0"
android:layout_margin="5dp"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:text="+" android:textSize="20sp" />
<Button android:id="@+id/btnminus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="1"
android:layout_margin="5dp"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:text="-" android:textSize="20sp" />
<Button android:id="@+id/btnmul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="2"
android:layout_margin="5dp"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:text="*" android:textSize="20sp" />
<Button android:id="@+id/btndiv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="3"
android:layout_margin="5dp"
16
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:text="/" android:textSize="20sp" /> </GridLayout>
17
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
<TextView android:id="@+id/textView2"
android:layout_width="361dp"
android:layout_height="57dp"
android:text="CALCULATOR"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textSize="48sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.139" />
</androidx.constraintlayout.widget.ConstraintLayout>
JAVA:
package com.example.calci;
import android.os.Bundle;
import
android.view.View;
import android.widget.Button;
import android.widget.EditText;
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;
18
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
int num1,num2;
@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;
});
Result = findViewById(R.id.result);
Num1 = findViewById(R.id.edt1);
Num2 = findViewById(R.id.edt2);
Add = findViewById(R.id.btnplus);
Sub = findViewById(R.id.btnminus);
Mul = findViewById(R.id.btnmul);
Div = findViewById(R.id.btndiv);
Add.setOnClickListener(this);
Sub.setOnClickListener(this);
Mul.setOnClickListener(this);
Div.setOnClickListener(this);
}
num1 = Integer.parseInt(Num1.getText().toString());
num2 = Integer.parseInt(Num2.getText().toString());
int id = view.getId();
if (id == R.id.btnplus){
19
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
if (id == R.id.btnminus){
num2));
if (id == R.id.btnmul){
Result.setText("Answer = " + (num1 * num2)); }
if (id == R.id.btndiv){
Result.setText("Answer = " + ((float)num1 / (float)num2)); }
}
}
20
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
OUTPUT:
21
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
Que5. 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 :
<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;
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;
22
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
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);
}
});
}
}
23
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
OUTPUT:
24
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
Que6: Write an android application that demonstrate the use of radio and checkbox button, your app
should allow user to select multiple food preferences using check boxes and choose their favorite
drink using radio buttons.
1. XML (activity_main.xml):
<CheckBox android:id="@+id/checkbox_burger"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Burger" />
<CheckBox android:id="@+id/checkbox_pasta"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pasta" />
android:textStyle="bold"
android:layout_marginTop="16dp"
android:layout_marginBottom="8dp" />
<RadioButton android:id="@+id/radio_tea"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tea" />
<RadioButton android:id="@+id/radio_coffee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Coffee" />
<RadioButton android:id="@+id/radio_juice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Juice" /> </RadioGroup>
JAVA:
package com.example.fooddrinkselection;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
26
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import
androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize Views
checkBoxPizza = findViewById(R.id.checkbox_pizza);
checkBoxBurger = findViewById(R.id.checkbox_burger);
checkBoxPasta = findViewById(R.id.checkbox_pasta);
radioGroupDrinks =
findViewById(R.id.radioGroup_drinks);
btnSubmit = findViewById(R.id.btn_submit);
textViewResult = findViewById(R.id.textView_result);
} else {
drinkPreference = "Drink: None selected"; }
// Display Results
String result = foodPreferences.toString().trim() + "\n" + drinkPreference;
textViewResult.setText(result); } });
}
}
28
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
OUTPUT:
29
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
Que7. Write an application to create a database and perform insertion operation. (For Example:
Create a database name studentDB where the attributes are name, roll no, course and average
marks.)
CODE:
1. Database Helper Class (StudentDatabaseHelper.java)
This class manages the creation of the database and handles the insertion operation.
JAVA:
package com.example.studentdb;
import android.content.ContentValues;
import android.content.Context;
import
android.database.sqlite.SQLiteDatabase;
import
android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;
@Override
public void onCreate(SQLiteDatabase db) {
String createTableQuery = "CREATE TABLE " + TABLE_NAME + " (" +
COLUMN_ROLL_NO + " INTEGER PRIMARY KEY, " +
COLUMN_NAME + "
30
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db); }
public boolean insertStudent(int rollNo, String name, String course, float averageMarks) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(COLUMN_ROLL_NO, rollNo);
values.put(COLUMN_NAME, name);
values.put(COLUMN_COURSE, course);
values.put(COLUMN_AVERAGE_MARKS, averageMarks);
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;
31
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize views
editTextRollNo = findViewById(R.id.editTextRollNo);
editTextName = findViewById(R.id.editTextName);
editTextCourse = findViewById(R.id.editTextCourse);
editTextAverageMarks = findViewById(R.id.editTextAverageMarks);
buttonInsert = findViewById(R.id.buttonInsert);
32
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
3. XML Layout
(activity_main.xml):
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/editTextRollNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Roll Number"
android:inputType="number" />
<EditText
android:id="@+id/editTextName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
33
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
android:inputType="textPersonName" />
<EditText
android:id="@+id/editTextCourse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Course"
android:inputType="text" />
<EditText
android:id="@+id/editTextAverageMarks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Average Marks"
android:inputType="numberDecimal" />
<Button
android:id="@+id/buttonInsert"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Insert" /> </LinearLayout>
34
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
Que8. Write an android application to perform update when the user wants to update any field with
the help of roll no and delete with the help of roll no.
CODE:
@Override
public void onCreate(SQLiteDatabase db) {
String createTableQuery = "CREATE TABLE " + TABLE_NAME + " (" +
COLUMN_ROLL_NO + " INTEGER PRIMARY KEY, " +
COLUMN_NAME + " TEXT, " +
COLUMN_COURSE + " TEXT, " +
COLUMN_AVERAGE_MARKS + " REAL);";
db.execSQL(createTableQuery);
Toast.makeText(context, "Database Created", Toast.LENGTH_SHORT).show();
}
@Override
35
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
public boolean updateStudent(int rollNo, String name, String course, float averageMarks) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(COLUMN_NAME, name);
values.put(COLUMN_COURSE, course);
values.put(COLUMN_AVERAGE_MARKS, averageMarks);
2. MainActivity.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
36
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
// Initialize views
editTextRollNo = findViewById(R.id.editTextRollNo);
editTextName = findViewById(R.id.editTextName);
editTextCourse = findViewById(R.id.editTextCourse);
editTextAverageMarks = findViewById(R.id.editTextAverageMarks);
buttonUpdate = findViewById(R.id.buttonUpdate);
buttonDelete = findViewById(R.id.buttonDelete);
try {
int rollNo = Integer.parseInt(editTextRollNo.getText().toString());
String name = editTextName.getText().toString();
String course = editTextCourse.getText().toString();
float averageMarks = Float.parseFloat(editTextAverageMarks.getText().toString());
boolean isUpdated = dbHelper.updateStudent(rollNo, name, course, averageMarks);
if (isUpdated) {
Toast.makeText(MainActivity.this, "Student updated successfully",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "Error: Roll Number not found",
Toast.LENGTH_SHORT).show();
}
}
catch (NumberFormatException e) {
Toast.makeText(MainActivity.this, "Please enter valid data",
Toast.LENGTH_SHORT).show();
}
}
37
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
});
if (isDeleted) {
Toast.makeText(MainActivity.this, "Student deleted successfully",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "Error: Roll Number not found",
Toast.LENGTH_SHORT).show();
}
}
catch (NumberFormatException e) {
Toast.makeText(MainActivity.this, "Please enter a valid Roll Number",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
<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/editTextRollNo"
38
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Roll Number (required)"
android:inputType="number" />
<EditText
android:id="@+id/editTextName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:inputType="textPersonName" />
<EditText
android:id="@+id/editTextCourse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Course"
android:inputType="text" />
<EditText
android:id="@+id/editTextAverageMarks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Average Marks"
android:inputType="numberDecimal" />
<Button
android:id="@+id/buttonUpdate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Update Student" />
<Button
android:id="@+id/buttonDelete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Delete Student"
android:layout_marginTop="8dp" />
</LinearLayout>
39
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
OUTPUT:
40
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
Que9. Write an android application to display google map with the marker location of India.
CODE:
1. MainActivity.java
package com.example.mymap;
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.mymap.databinding.ActivityMapsBinding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMapsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
2. AndroidManifest.xml:
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyMap"
tools:targetApi="31"
tools:ignore="ExtraText">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyCBOHAPFv8Iqayo8snszWNdtK9kBlKY8Sc" />
<activity
android:name=".MapsActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
42
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
Que10. With the help of SMS-Manager class, write an application to send SMS.
CODE:
1. SMS MainActivity.java:
package com.example.mysms;
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 {
43
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
catch (Exception e) {
Toast.makeText(this, "SMS Sending Failed: " + e.getMessage(),Toast.LENGTH_SHORT).show();
}
} else {
@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();
}
}
}
}
44
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
2. 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">
<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>
45
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
3. AndroidManifest.xml:
<uses-feature
android:name="android.hardware.telephony"
android:required="false" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MySMS"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
</intent-filter>
</activity>
</application>
</manifest>
46
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
Que11: Write an android application to perform login, where it will take place by authenticating
the credentials form the data base.
CODE:
1. AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET"/>
2. Activity_main.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/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword" />
<Button
android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login" />
</LinearLayout>
3. MainActivity.java:
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
47
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
import androidx.appcompat.app.AppCompatActivity;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.MediaType;
import org.json.JSONObject;
import java.io.IOException;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
usernameEditText = findViewById(R.id.username);
passwordEditText = findViewById(R.id.password);
loginButton = findViewById(R.id.loginButton);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
login();
}
});
}
48
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
try {
json.put("username", username);
json.put("password", password);
}
catch (Exception e) {
e.printStackTrace();
}
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
runOnUiThread(() -> Toast.makeText(MainActivity.this, "Login failed: " +
e.getMessage(), Toast.LENGTH_SHORT).show());
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (response.isSuccessful()) {
runOnUiThread(() -> Toast.makeText(MainActivity.this, "Login successful",
Toast.LENGTH_SHORT).show());
} else {
runOnUiThread(() -> Toast.makeText(MainActivity.this, "Login failed: " +
response.message(), Toast.LENGTH_SHORT).show());
}
}
});
}
}
49
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
STEPS:
1. Complete Development: Ensure your app is fully developed, tested, and free of critical
bugs.
2. Versioning: Update the version number in your build.gradle file. This is crucial for future
updates.
3. Remove Debugging Code: Ensure that any debugging code, logging, or development tools
are removed or disabled.
4. Sign Your App: You need to sign your app with a release key. This is done using Android
Studio or the command line.
A. Using Android Studio:
1. Go to Build > Generate Signed Bundle / APK.
2. Select APK and click Next.
3. Choose your module, and click Next.
4. Create or select a keystore, enter the necessary details, and click Next.
5. Choose the build type (usually release) and click Finish.
5. Optimize Your App: Use ProGuard or R8 for code shrinking and obfuscation to reduce the
size of your APK and protect your code.
50
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
1. Sign Up for a Developer Account: Go to the Google Play Console and sign up for a
developer account. There is a one-time registration fee (currently $25).
2. Complete Your Account Setup: Fill in the required information, including your developer
name, email, and contact information.
1. Go to the App Releases Section: In the Play Console, navigate to the Release section.
2. Create a New Release:
i. Click on Production and then Create new release.
ii. Upload your signed APK or App Bundle.
iii. Fill in the release notes for this version.
3. Review and Roll Out: Review your release details and click on Review to ensure
everything is correct. Then click on Start rollout to production.
1. Check for Errors: Google Play Console will check for errors and compliance issues.
Resolve any issues if they arise.
2. Roll Out the Release: Once everything is set, click on Roll out to production to publish
your app.
3. Wait for Review: Your app will go through a review process. This can take a few hours to
a few days. You will be notified once the review is complete.
51
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)
STEP 6: POST-PUBLICATION:
1. Monitor Your App: After your app is published, monitor its performance, user reviews, and
ratings in the Play Console.
2. Respond to User Feedback: Engage with users by responding to reviews and addressing
concerns.
3. Update Your App: Regularly update your app to fix bugs, add features, and improve user
experience. Increment the version code and version name with each update.
4. Promote Your App: Use social media, blogs, and other marketing channels to promote
your app and increase visibility.
52