0% found this document useful (0 votes)
13 views52 pages

AndroidFinal AK

Uploaded by

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

AndroidFinal AK

Uploaded by

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

NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)

Que1: How to install and setup Android Studio.

Steps:

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.

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.

Step 6: This will start the Android Studio.

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.

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

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

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

public class MainActivity extends AppCompatActivity {


Button btn ;
TextView txt ;
@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;
});
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

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

public class MainActivity extends AppCompatActivity {


Button btn ;
TextView txt ;
@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;
});
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 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

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

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

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

app:layout_constraintVertical_bi as="0.106" />

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

public class MainActivity extends AppCompatActivity implements


View.OnClickListener {
TextView Result;
EditText Num1, Num2;

18
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)

Button Add, Sub, Mul, Div ;

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);
}

@Override public void onClick(View view) {

num1 = Integer.parseInt(Num1.getText().toString());

num2 = Integer.parseInt(Num2.getText().toString());

int id = view.getId();

if (id == R.id.btnplus){

Result.setText("Answer = " + (num1 + num2)); }

19
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)

if (id == R.id.btnminus){

Result.setText("Answer = " + (num1

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 :

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

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);
}
});
}
}

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):

<?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:textStyle="bold"
android:layout_marginBottom="8dp" />

<!-- CheckBox for Food Preferences -->


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

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

<!-- Title for Drink Selection -->


<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
25
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)

android:text="Choose Your Favorite Drink"


android:textSize="18sp"

android:textStyle="bold"
android:layout_marginTop="16dp"
android:layout_marginBottom="8dp" />

<!-- RadioGroup for Drinks -->


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

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

<!-- Submit Button -->


<Button
android:id="@+id/btn_submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_marginTop="16dp" /></LinearLayout>

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;

public class MainActivity extends AppCompatActivity {


private CheckBox checkBoxPizza, checkBoxBurger, checkBoxPasta;
private RadioGroup radioGroupDrinks;
private Button btnSubmit;
private TextView textViewResult;

@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);

// Set Submit Button Click Listener


btnSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Collect Food Preferences
StringBuilder foodPreferences = new StringBuilder("Food: ");
if (checkBoxPizza.isChecked()) foodPreferences.append("Pizza ");
if (checkBoxBurger.isChecked()) foodPreferences.append("Burger ");
if (checkBoxPasta.isChecked()) foodPreferences.append("Pasta ");

// Collect Favorite Drink


int selectedDrinkId = radioGroupDrinks.getCheckedRadioButtonId();
String drinkPreference = "";
if (selectedDrinkId != -1) {
RadioButton selectedDrink = findViewById(selectedDrinkId);
drinkPreference = "Drink: " + selectedDrink.getText().toString();
27
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)

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

public class StudentDatabaseHelper 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 =
"roll_no";
private static final String COLUMN_COURSE =
"course";
private static final String COLUMN_AVERAGE_MARKS = "average_marks";
private Context context;

public StudentDatabaseHelper(Context context) {


super(context, DATABASE_NAME, null,
DATABASE_VERSION);
this.context = context;
}

@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)

TEXT, " + COLUMN_COURSE + " TEXT, " +


COLUMN_AVERAGE_MARKS +
" REAL);";
db.execSQL(createTableQuery);
Toast.makeText(context, "Database Created", Toast.LENGTH_SHORT).show();
}

@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);

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


return result != -1; // Returns true if insertion is
successful
}
}

2. Activity to Perform Insert Operation (MainActivity.java)


This activity contains a form to enter the student details and a button to insert the
data. 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 {

31
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)

private EditText editTextRollNo, editTextName, editTextCourse,


editTextAverageMarks;
private Button buttonInsert;
private StudentDatabaseHelper dbHelper;

@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);

// Initialize database helper

dbHelper = new StudentDatabaseHelper(this);

// Set click listener for insert button


buttonInsert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
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());

// Insert data into database


boolean isInserted = dbHelper.insertStudent(rollNo, name, course,
averageMarks);
if (isInserted) {
Toast.makeText(MainActivity.this, "Student inserted successfully",
Toast.LENGTH_SHORT).show();
clearFields();
} else {

32
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)

Toast.makeText(MainActivity.this, "Error inserting student",


Toast.LENGTH_SHORT).show();
}
} catch (NumberFormatException e) {
Toast.makeText(MainActivity.this, "Please enter valid data",
Toast.LENGTH_SHORT).show();
}
}
});
}

private void clearFields() {


editTextRollNo.setText("");
editTextName.setText("");
editTextCourse.setText("");
editTextAverageMarks.setText("");
}
}

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:

1. Database Helper Class (StudentDatabaseHelper.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;

public class StudentDatabaseHelper 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 = "roll_no";
private static final String COLUMN_COURSE = "course";
private static final String COLUMN_AVERAGE_MARKS = "average_marks";
private Context context;

public StudentDatabaseHelper(Context context) {


super(context, DATABASE_NAME, null,
DATABASE_VERSION);
this.context = context; }

@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 void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {


db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}

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);

int result = db.update(TABLE_NAME, values, COLUMN_ROLL_NO + "=?", new


String[]{String.valueOf(rollNo)});
return result > 0; // Returns true if at least one row was updated
}

public boolean deleteStudent(int rollNo) {


SQLiteDatabase db = this.getWritableDatabase();
int result = db.delete(TABLE_NAME, COLUMN_ROLL_NO + "=?", new
String[]{String.valueOf(rollNo)});
return result > 0; // Returns true if at least one row was deleted
}
}

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;

public class MainActivity extends AppCompatActivity {


private EditText editTextRollNo, editTextName, editTextCourse, editTextAverageMarks;
private Button buttonUpdate, buttonDelete;
private StudentDatabaseHelper dbHelper;

@Override
36
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)

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);
buttonUpdate = findViewById(R.id.buttonUpdate);
buttonDelete = findViewById(R.id.buttonDelete);

// Initialize database helper


dbHelper = new StudentDatabaseHelper(this);

// Update button functionality


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

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)

});

// Delete button functionality


buttonDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
int rollNo =
Integer.parseInt(editTextRollNo.getText().toString());
boolean isDeleted = dbHelper.deleteStudent(rollNo);

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();
}
}
});
}
}

3. XML Layout (activity_main.xml):


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

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">

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

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());

// 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;

// Add a marker in Sydney and move the camera


LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
41
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)

2. AndroidManifest.xml:

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


<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.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;

public class MainActivity extends AppCompatActivity {


private static final int SMS_PERMISSION_REQUEST_CODE = 101;
private EditText phoneNumber, 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 {

43
NAME:ALOK KUMAR SEM:MCA(3rd)/C ROLL:2301040(06)

// Permission already granted, send SMS


sendSms(); }
});
}

private void sendSms() {


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();
}
}
}
}

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:

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


<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-feature
android:name="android.hardware.telephony"
android:required="false" />

<uses-permission android:name="android.permission.SEND_SMS" />


<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />

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

<action android:name="android.intent.action.MAIN" />

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

</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;

public class MainActivity extends AppCompatActivity {

private EditText usernameEditText;


private EditText passwordEditText;
private Button loginButton;

private static final String LOGIN_URL = "http://your-server-ip:3000/login";

@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();
}
});
}

private void login() {


String username = usernameEditText .getText().toString();
String password = passwordEditText.getText().toString();

OkHttpClient client = new OkHttpClient();


MediaType JSON = MediaType.get("application/json; charset=utf-8");
JSONObject json = new JSONObject();

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();
}

RequestBody body = RequestBody.create(json.toString(), JSON);


Request request = new Request.Builder().url(LOGIN_URL).post(body).build();

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)

Que12: State step by step procedure to publish an application in play store.

STEPS:

STEP 1: PREPARE YOUR APP FOR RELEASE:

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)

STEP 2: CREATE A GOOGLE PLAY DEVELOPER ACCOUNT:

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.

STEP 3: PREPARE STORE LISTING:

1. Create a New App:


A. In the Google Play Console, click on Create App.
B. Select the app type (App or Game), choose a language, and enter the app name.
2. Fill Out Store Listing:
A. Product Details: Enter the app title, description, and other details.
B. Graphics: Upload high-resolution app icons, feature graphics, and screenshots.
Recommended sizes:
i. App Icon: 512 x 512 pixels
ii. Feature Graphic: 1024 x 500 pixels
iii. Screenshots: 1280 x 800 pixels or higher (landscape), or 1080 x 1920 pixels
(portrait)
C. Categorization: Select the appropriate category for your app (e.g., Games,
Productivity).
3. Content Rating: Fill out the content rating questionnaire to receive a rating for your app.
4. Privacy Policy: If your app collects user data, provide a URL to your privacy policy.

STEP 4: UPLOAD YOUR APK OR APP BUNDLE:

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.

STEP 5: PUBLISH YOUR APP:

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

You might also like