0% found this document useful (0 votes)
23 views120 pages

Android - Practicals H.

Uploaded by

hunnygamer584
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)
23 views120 pages

Android - Practicals H.

Uploaded by

hunnygamer584
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/ 120

Subject: Mobile Application Development using Android Sub-Code: 4350703

En. No: 226420307083

Practical -1
Aim : Set-up of Android development environment, managing AVD and
understanding its various components.

Environment setup for Android apps Development :-

To setup an environment for the Android application development, you will need to
download and install the following :

✓ Java Development Kit (JDK) 5 or 6


✓ The Android SDK
✓ Eclipse

Step 1 : Download and Install JDK

➢ The Android SDK makes use of the Java SE Development Kit (JDK). If your
computer does not have the JDK installed , you should start by downloading it
from: www.oracle.com/technetwork/java/javase/downloads/index.html and
installing it prior to moving to the next section.

Step 2 : Download Android Development Environment


Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

➢ There are a number of ways to develop Android apps. The easiest way to get
started quickly is to use the ADT Bundle developed by Google. The ADT Bundle
provides a number of tools that are essential to building android apps.

➢ To download ADT bundle go to https://developer android.com/sdk/index.html.


On this web page click on the button "Download the SDK" as shown in below
figure.

➢ When you click on this button, it will ask to agree on terms and condition, now
click the checkbox agreeing to the terms and conditions and select either 32-bit
or 64-bit, depending on your computer. After you have agreed and selected your
system type click on the "Download the SDK ADT Bundle for Windows" button
and the download will start. The downloaded file is a zip file.
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Step 3 : Installing the ADT bundle

➢ Once downloading of the ADT Bundle has completed, Extract all the files to a
location on your computer. You will find two folders named eclipse and sdk and
an application called SDK Manager as shown in below figure.

➢ Now you are going to open up the environment where you will be developing
android applications by click on eclipse folder. You will now see multiple folders
and files as sown in below figure. You need to double click on eclipse.exe to open
the eclipse. Once eclipses get started, you can start building your first application.
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Create an AVD

1. Open the AVDManager byclicking Tools >AVD Manager.


2. Click CREATEVIRTUAL DEVICE,at the bottom ofthe AVD Managerdialog.
3. The SelectHardware pageappears.4.
4. Select a hardwareprofile, and then click

If you don't see the hardware profile you want, than you

can create or import ahardware profile.6.

The System Image page appears

Select the system image for a particular API level, and then click

NEXT

The RECOMMENDED tab lists recommended system images. The other tabs
includea more complete list. The right pane describes the selected system image. x86images
run the fastest in the emulator.

9.If you see DOWNLOAD next to the system image, you need to click it to downloadthe
system image. You must be connected to the internet to download it.

10. The API level of the target device is important, because your app won't be able
to runon a system image with an API level that's less than that required by your app,
asspecified in the minSdkVersion attribute of the app manifest file.
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Practical – 2
Aim :- Understanding of Various Components available in Android
Application.

Android applications are composed of various components that work together to


create a seamless user experience. These components are building blocks of an
Android app and serve different purposes. Here's an overview of the main Android
application components:

Activities:

Activities represent the user interface or screens in an Android app. Each screen that
the user interacts with is typically implemented as an activity. Activities can be
started and stopped, and they can transition from one to another, providing the app's
user interface.

Fragments:

Fragments are smaller, reusable portions of an activity's UI. They allow for more
modular and flexible user interfaces. Multiple fragments can be combined in a single
activity to create multi-pane UIs, particularly useful for tablets and larger screens.

Services:

Services are background processes that run independently of the UI and are used for
tasks that don't require direct user interaction. Common use cases include playing
music in the background, handling network operations, or performing periodic data
updates.

Broadcast Receivers:

Broadcast receivers are components that listen for system-wide broadcast


announcements, such as low battery warnings, incoming SMS messages, or changes
in network connectivity. They can trigger specific actions when these events occur.
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Content Providers:

Content providers allow apps to share data with other apps. They provide a
structured way to access and modify data stored in a centralized repository, such as
a SQLite database. Content providers are commonly used for data sharing in
Android, including contacts, calendars, and media files.

Intents:

Intents are a messaging system used to request actions from other app components.
They can be used to start activities, services, or broadcast messages to inform other
components about specific events or actions. Intents can be explicit (targeting a
specific component) or implicit (letting the system choose an appropriate
component).

Notifications:

Notifications are a way to alert the user about events or updates in the app, even
when the app is not currently in the foreground. They can be displayed in the
system's notification tray and can include text, images, and actions for the user to
interact with.

Widgets:

Widgets are small, interactive components that can be added to the home screen of
a device. They provide quick access to specific app functionality or information,
without the need to open the full app.

Manifest File:

The AndroidManifest.xml file contains metadata about the app and its components.
It specifies the app's package name, permissions, and the main components, allowing
the Android system to understand and manage the app.
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Practical – 3
Aim :- Develop a “Hello World” Application in Android and understand the
structure of an Android Application.

Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
a1ndroid:layout_height="match_parent"
tools:context=".MainActivity">

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

</androidx.constraintlayout.widget.ConstraintLayout>
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

JAVA FILE :

package com.example.sample;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

}
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Practical – 4
Aim :- Develop Android Application to demonstrate methods of Activity Life
Cycle.
ACTIVITY_MAIN.XML:

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent">

<TextView

android:id="@+id/lifecycleEventsTextView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Lifecycle events will appear here."

android:layout_centerInParent="true" />

</RelativeLayout>

JAVA FILE :

package com.example.sample;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.util.Log;

import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

private static final String TAG = "ActivityLifecycle";

private TextView lifecycleEventsTextView;


Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

lifecycleEventsTextView = findViewById(R.id.lifecycleEventsTextView);

logLifecycleEvent("onCreate");

@Override

protected void onStart() {

super.onStart();

logLifecycleEvent("onStart");

@Override

protected void onResume() {

super.onResume();

logLifecycleEvent("onResume");

@Override

protected void onPause() {

super.onPause();

logLifecycleEvent("onPause");

@Override
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

protected void onStop() {

super.onStop();

logLifecycleEvent("onStop");

@Override

protected void onRestart() {

super.onRestart();

logLifecycleEvent("onRestart");

@Override

protected void onDestroy() {

super.onDestroy();

logLifecycleEvent("onDestroy");

private void logLifecycleEvent(String event) {

String message = "Lifecycle Event: " + event + "\n";

lifecycleEventsTextView.append(message);

Log.d(TAG, event);

}
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Practical-5
Aim: Design Android Activities using LinearLayout, RelativeLayout,
GridView, FrameLayout, and ConstraintLayout.

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

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Hello World!"

android:textSize="24sp"/>

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Click Me"/>

</LinearLayout>
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Mainactivity.java
package com.example.myapplication

import androidx.appcompat.app.AppCompatActivity

import android.os.Bundle

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)

setContentView(R.layout.activity_main)

Output
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

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

<FrameLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

<TextView

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:text="Hello RMS"

android:textSize="40sp"

android:textStyle="bold"

android:gravity="center"/>

<ImageView

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:scaleType="fitCenter"

/>

</FrameLayout>
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

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

<TableLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="#ffff00"

android:stretchColumns="0"

>
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

<TableRow>

<Button

android:id="@+id/button1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="1" />

</TableRow>

<TableRow>

<Button

android:id="@+id/button2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="2" />

<Button

android:id="@+id/button3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="3" />

</TableRow>

</TableLayout>
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

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

<GridLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="#ffffff"

android:columnCount="3"

android:rowCount="3"

>

<Button

android:id="@+id/button1"

android:layout_column="0"

android:layout_row="0"
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

android:padding="35dp"

android:text="[0,0]" />

<Button

android:id="@+id/button2"

android:layout_column="1"

android:layout_row="0"

android:padding="35dp"

android:text="[0,1]" />

<Button

android:id="@+id/button3"

android:layout_column="0"

android:layout_row="1"

android:padding="35dp"

android:text="[1,0]" />

<Button

android:id="@+id/button4"

android:layout_column="1"

android:layout_row="1"

android:padding="35dp"

android:text="[1,1]" />

<Button

android:id="@+id/button5"

android:layout_column="2"

android:layout_row="0"

android:padding="35dp"
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

android:text="[0,2]" />

<Button

android:id="@+id/button6"

android:layout_column="2"

android:layout_row="1"

android:padding="35dp"

android:text="[1,2]" />

</GridLayout>
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

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

<RelativeLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

>

<TextView

android:id="@+id/text1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:layout_centerInParent="false"

android:text="LOGIN"

android:layout_margin="14dp"

android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView

android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/text1"

android:layout_marginTop="20dp"

android:text="Username:"

android:textAppearance="?android:attr/textAppearanceLarge" />
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

<EditText

android:id="@+id/editText1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:layout_alignTop="@+id/textView1"

android:layout_toRightOf="@+id/textView1" />

<TextView

android:id="@+id/textView2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/textView1"

android:layout_marginTop="20dp"

android:text="Password:"

android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText

android:id="@+id/editText2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:layout_alignTop="@+id/textView2"

android:layout_toRightOf="@+id/textView2"

android:inputType="textPassword"/>
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

<Button

android:id="@+id/btnSubmit"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentLeft="false"

android:layout_below="@+id/editText2"

android:layout_centerInParent="true"

android:text="Submit" />

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:layout_centerHorizontal="true"

android:text="SIGNUP" />

</RelativeLayout>
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Practical- 6
AIM:- Design various Activities using different Layouts and available Widgets
(TextView, EditText, Button, RadioButton, CheckBox, ImageButton,
ToggleButton, TimePicker, DatePicker, ProgressBar, ImageView) to make the
user-friendly GUI.

1. MainActivity (Linear Layout with EditText and Button):

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

<EditText android:id="@+id/etName"

android:layout_width="match_parent"

android:layout_height="wrap_content" android:hint="Enter your name" />

<Button

android:id="@+id/btnSubmit"

android:layout_width="wrap_content"

android:layout_height="wrap_content" android:text="Submit" />

</LinearLayout>
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Second Layout (Relative Layout with CheckBox, RadioButton, and


ToggleButton)

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent">

<CheckBox android:id="@+id/chkSound"

android:layout_width="wrap_content"

android:layout_height="wrap_content"
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

android:text="Enable Sound" />

<RadioButton android:id="@+id/radioOption1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@id/chkSound"

android:text="Option 1" />

<RadioButton android:id="@+id/radioOption2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@id/radioOption1"

android:text="Option 2" />

<ToggleButton android:id="@+id/toggleButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@id/radioOption2"

android:textOff="Off"

android:textOn="On" />

</RelativeLayout>
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Third Layout (Constraint Layout with TimePicker and DatePicker)


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

android:layout_width="match_parent"

android:layout_height="match_parent"

android:padding="16dp">

<TimePicker android:id="@+id/timePicker"
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

android:layout_width="wrap_content"

android:layout_height="wrap_content"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintEnd_toEndOf="parent"

android:layout_marginTop="20dp" />

<DatePicker android:id="@+id/datePicker"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

app:layout_constraintTop_toBottomOf="@id/timePicker"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintEnd_toEndOf="parent"

android:layout_marginTop="20dp" />

</androidx.constraintlayout.widget.ConstraintLayout>
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Fourth Layout (Frame Layout with ProgressBar )


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

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center">

<ProgressBar android:id="@+id/progressBar"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:indeterminate="true" />

<ImageView android:id="@+id/imageView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

android:src="@drawable/ic_launcher_foreground"

android:contentDescription="Sample Image1"

android:visibility="gone" />

</FrameLayout>
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Practical – 7
Aim :- Develop code to demonstrate different ways of Handling
different events (onClick, onLongClick etc.) over Button, EditText
etc. to perform action in Android application at run-time.

<?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:gravity="center_horizontal|center_vertical">

<TextView

android:id="@+id/text_view"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textSize="24sp"

android:text="HELLO RMS"

android:textStyle="bold"/>

<LinearLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="horizontal">
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

<Button

android:id="@+id/red_button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Red"

style="?android:attr/buttonBarButtonStyle" />

<Button

android:id="@+id/green_button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Green"

style="?android:attr/buttonBarButtonStyle" />

<Button

android:id="@+id/blue_button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Blue"

style="?android:attr/buttonBarButtonStyle" />

</LinearLayout>

</LinearLayout>
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

JAVA FILE :
package com.example.sample;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.graphics.Color;

import android.widget.Button;

import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

private TextView textView;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

textView = findViewById(R.id.text_view);

Button redButton = findViewById(R.id.red_button);

redButton.setOnClickListener(v -> textView.setTextColor(Color.RED));

Button greenButton = findViewById(R.id.green_button);


Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

greenButton.setOnClickListener(v -> textView.setTextColor(Color.GREEN));

Button blueButton = findViewById(R.id.blue_button);

blueButton.setOnClickListener(v -> textView.setTextColor(Color.BLUE));

}
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Practical – 8
Aim :- Develop code to demonstrate Event handling of CheckBox
and RadioButton selection.

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context="com.example.krishnapr8.MainActivity" >

<TextView

android:id="@+id/tvRg"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:gravity="center"

android:text="Select Your semester"

android:textAppearance="?android:attr/textAppearanceMedium" />

<RadioGroup

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_below="@+id/tvRg"

android:layout_centerHorizontal="true"

android:orientation="horizontal"
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

android:showDividers="beginning|middle|end"

android:layout_marginTop="10dp"

android:id="@+id/radioGroup" >

<RadioButton

android:id="@+id/rb1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="1ST"

android:checked="false" />

<RadioButton

android:id="@+id/rb2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="3RD"

android:checked="true" />

<RadioButton

android:id="@+id/rb3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="5TH"

android:checked="false" />

</RadioGroup>

<Button

android:layout_width="wrap_content"
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

android:layout_height="wrap_content"

android:text="SUBMIT"

android:id="@+id/btnSubmit"

android:layout_below="@+id/cb4"

android:layout_centerHorizontal="true"

android:layout_marginTop="10dp"/>

<TextView

android:id="@+id/tvCb"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_below="@+id/radioGroup"

android:gravity="center"

android:text="Select your subject as per your semester"

android:layout_marginTop="65dp"

android:textAppearance="?android:attr/textAppearanceMedium"/>

<CheckBox

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="BASIC ELECTRONICS"

android:id="@+id/cb1"

android:layout_below="@+id/tvCb"

android:layout_centerHorizontal="true"

android:checked="false"/>

<CheckBox

android:layout_width="match_parent"
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

android:layout_height="wrap_content"

android:text="DATA STRUCTURES AND ALGORITHMS"

android:id="@+id/cb2"

android:layout_below="@+id/cb1"

android:layout_centerHorizontal="true"

android:checked="false"/>

<CheckBox

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="MACHINE LEARNING"

android:id="@+id/cb3"

android:layout_below="@+id/cb2"

android:layout_centerHorizontal="true"

android:checked="false"/>

<CheckBox

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="ARTIFICIAL INTELLIGENCE"

android:id="@+id/cb4"

android:layout_below="@+id/cb3"

android:layout_centerHorizontal="true"

android:checked="false"/>

</RelativeLayout>
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

JAVA FILE :
package com.example.sample;

import androidx.appcompat.app.AppCompatActivity;

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;

public class MainActivity extends AppCompatActivity {

RadioGroup radioGroup;

RadioButton selectedRadioButton;

Button buttonSubmit;

CheckBox cb1, cb2, cb3, cb4; // Declare CheckBox variables

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// Initialize RadioGroup and Button

buttonSubmit = findViewById(R.id.btnSubmit);

radioGroup = findViewById(R.id.radioGroup);
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

// Initialize CheckBox variables

cb1 = findViewById(R.id.cb1);

cb2 = findViewById(R.id.cb2);

cb3 = findViewById(R.id.cb3);

cb4 = findViewById(R.id.cb4);

buttonSubmit.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

// Handle RadioButton selection

selectedRadioButton = findViewById(radioGroup.getCheckedRadioButtonId());

String yourVote = selectedRadioButton.getText().toString();

// Handle CheckBox states

StringBuilder checkBoxChoices = new StringBuilder();

if (cb1.isChecked()) {

checkBoxChoices.append(cb1.getText().toString()).append("\tYES\n");

} else {

checkBoxChoices.append(cb1.getText().toString()).append("\tNO\n");

if (cb2.isChecked()) {

checkBoxChoices.append(cb2.getText().toString()).append("\tYES\n");

} else {
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

checkBoxChoices.append(cb2.getText().toString()).append("\tNO\n");

if (cb3.isChecked()) {

checkBoxChoices.append(cb3.getText().toString()).append("\tYES\n");

} else {

checkBoxChoices.append(cb3.getText().toString()).append("\tNO\n");

if (cb4.isChecked()) {

checkBoxChoices.append(cb4.getText().toString()).append("\tYES\n");

} else {

checkBoxChoices.append(cb4.getText().toString()).append("\tNO\n");

// Display the results

Toast.makeText(MainActivity.this,

"Selected Radio Button is: " + yourVote + "\nCheckBox Choices:\n" +


checkBoxChoices.toString(),

Toast.LENGTH_LONG).show();

});

}
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Practical - 9
Aim :- Develop code to navigate between different activities and pass
the data from one activity to other activity using Intent.
Activity_main.xml
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<TextView

android:id="@+id/textView3"

android:layout_width="95dp"

android:layout_height="48dp"

android:layout_marginEnd="32dp"

android:text="Name"

android:textSize="22sp"

android:textColor="#000000"

android:textStyle="bold"

app:layout_constraintBaseline_toBaselineOf="@+id/mName"

app:layout_constraintEnd_toStartOf="@+id/mName" />

<EditText

android:id="@+id/mName"
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

android:padding="16dp"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="20dp"

android:layout_marginEnd="20dp"

android:ems="10"

android:inputType="textPersonName"

android:hint="name"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintTop_toTopOf="parent" />

<TextView

android:id="@+id/textView4"

android:layout_width="93dp"

android:layout_height="48dp"

android:layout_marginEnd="32dp"

android:text="Age"

android:textColor="#000000"

android:textSize="22sp"

android:textStyle="bold"

app:layout_constraintBaseline_toBaselineOf="@+id/mAge"

app:layout_constraintEnd_toStartOf="@+id/mAge"

app:layout_constraintHorizontal_bias="1.0"

app:layout_constraintStart_toStartOf="parent" />

<EditText

android:id="@+id/mAge"
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

android:padding="16dp"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="20dp"

android:layout_marginEnd="20dp"

android:ems="10"

android:inputType="number"

android:hint="age"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintTop_toBottomOf="@+id/mName" />

<Button

android:id="@+id/button2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="80dp"

android:text="Send Data"

app:layout_constraintTop_toBottomOf="@+id/mAge"

tools:layout_editor_absoluteX="156dp"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

import android.os.Bundle;

import android.view.View;

import android.widget.EditText;

import android.widget.Button;

public class MainActivity extends AppCompatActivity {

private EditText nameText,ageText;

private Button button;

private String name,age;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

nameText = findViewById(R.id.mName);

ageText = findViewById(R.id.mAge);

button = findViewById(R.id.button2);

button.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

sendData();

});

public void sendData()

name = nameText.getText().toString().trim();
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

age = ageText.getText().toString().trim();

Intent i =new Intent(MainActivity.this,MainActivity2.class);

i.putExtra(MainActivity2.NAME,name);

i.putExtra(MainActivity2.AGE,age);

startActivity(i);

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent">

<TextView

android:id="@+id/mName"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Name"

android:layout_margin="16dp"

android:textSize="18sp"

android:textColor="@android:color/black" />

<TextView

android:id="@+id/mAge"

android:layout_width="wrap_content"
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

android:layout_height="wrap_content"

android:text="Age"

android:layout_below="@id/mName"

android:layout_margin="16dp"

android:textSize="18sp"

android:textColor="@android:color/black" />

</RelativeLayout>

MainActivity2.java
package com.example.myapplication;

import android.content.Intent;

import android.os.Bundle;

import android.widget.TextView;

public class MainActivity2 extends MainActivity {

public static final String NAME = "NAME" ;

public static final String AGE = "AGE" ;

public TextView nameText,ageText ;

public String name,age;

@Override

protected void onCreate(Bundle savedInstanceState) {


Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main2);

nameText = findViewById(R.id.mName);

ageText = findViewById(R.id.mAge);

Intent i = getIntent();

name = i.getStringExtra(NAME);

age = i.getStringExtra(AGE);

nameText.setText(" "+ name);

ageText.setText("Age ="+age);

}
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Practical - 10
Aim :- Develop an android application to store data locally using
SharedPreferences and access-modify in different activities.

MAINACTIVITY.XML:
<RelativeLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin">

<EditText

android:id="@+id/etName"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:ems="10"

android:hint="Name"

android:inputType="text"

android:layout_alignParentTop="true"

android:layout_alignLeft="@+id/etEmail"

android:layout_alignStart="@+id/etEmail"
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

android:padding="16dp"/>

<EditText

android:id="@+id/etEmail"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:ems="10"

android:hint="Email"

android:inputType="textEmailAddress"

android:layout_below="@+id/etName"

android:layout_marginTop="20dp"

android:padding="16dp"

android:layout_alignParentRight="true"

android:layout_alignParentEnd="true" />

<Button

android:id="@+id/btnSave"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerVertical="true"

android:layout_alignParentLeft="true"

android:layout_alignParentStart="true"

android:onClick="Save"

android:text="Save" />
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

<Button

android:id="@+id/btnRetr"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:layout_centerVertical="true"

android:onClick="Get"

android:text="Retrieve" />

<Button

android:id="@+id/btnClear"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignRight="@+id/etEmail"

android:layout_centerVertical="true"

android:layout_alignParentRight="true"

android:layout_alignParentEnd="true"

android:onClick="clear"

android:text="Clear" />

</RelativeLayout>
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

MAINACTIVITY.JAVA:
package com.example.sample;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.content.Context;

import android.content.SharedPreferences;

import android.view.Menu;

import android.view.View;

import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

SharedPreferences sharedpreferences;

TextView name;

TextView email;

public static final String mypreference = "mypref";

public static final String Name = "nameKey";

public static final String Email = "emailKey";

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

name = (TextView) findViewById(R.id.etName);

email = (TextView) findViewById(R.id.etEmail);

sharedpreferences = getSharedPreferences(mypreference,

Context.MODE_PRIVATE);

if (sharedpreferences.contains(Name)) {
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

name.setText(sharedpreferences.getString(Name, ""));

if (sharedpreferences.contains(Email)) {

email.setText(sharedpreferences.getString(Email, ""));

} }

public void Save(View view) {

String n = name.getText().toString();

String e = email.getText().toString();

SharedPreferences.Editor editor = sharedpreferences.edit();

editor.putString(Name, n);

editor.putString(Email, e);

editor.commit(); }

public void clear(View view) {

name = (TextView) findViewById(R.id.etName);

email = (TextView) findViewById(R.id.etEmail);

name.setText("");

email.setText("");

public void Get(View view) {

name = (TextView) findViewById(R.id.etName);

email = (TextView) findViewById(R.id.etEmail);

sharedpreferences = getSharedPreferences(mypreference,

Context.MODE_PRIVATE);

if (sharedpreferences.contains(Name)) {

name.setText(sharedpreferences.getString(Name, ""));
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

if (sharedpreferences.contains(Email)) {

email.setText(sharedpreferences.getString(Email, ""));

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.menu_main, menu);

return true;

}
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Practical - 11
Aim : Develop the code to implement the ListView and the Spinner
views, perform add, update, remove items operations and implement
the item selection event handling over ListView and Spinner for
appropriate example.
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">

<Spinner

android:id="@+id/spinner"

android:padding="16dp"

android:layout_width="match_parent"

android:layout_height="wrap_content" />

<ListView

android:id="@+id/listView"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="16dp" />

<EditText
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

android:id="@+id/inputText"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Enter item" />

<Button

android:id="@+id/addButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Add Item" />

<Button

android:id="@+id/updateButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Update Item"

android:layout_marginTop="8dp" />

<Button

android:id="@+id/removeButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Remove Item"

android:layout_marginTop="8dp" />

</LinearLayout>
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

MAINACTIVITY.JAVA :
package com.example.sample;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.widget.ListView;

import android.view.View;

import android.widget.AdapterView;

import android.widget.ArrayAdapter;

import android.widget.EditText;

import android.widget.Spinner;

import android.widget.Toast;

import java.util.ArrayList;

import java.util.List;

public class MainActivity extends AppCompatActivity {

private ListView listView;

private Spinner spinner;

private List<String> listViewItems;

private ArrayAdapter<String> listViewAdapter;

private ArrayAdapter<String> spinnerAdapter;

private int selectedItemPosition = -1; // For updating items

@Override
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

listView = findViewById(R.id.listView);

spinner = findViewById(R.id.spinner);

// Initialize list view and spinner data

listViewItems = new ArrayList<>();

listViewAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,


listViewItems);

listView.setAdapter(listViewAdapter);

List<String> spinnerItems = new ArrayList<>();

spinnerItems.add("Item 1");

spinnerItems.add("Item 2");

spinnerItems.add("Item 3");

spinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item,


spinnerItems);

spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

spinner.setAdapter(spinnerAdapter);

// Add item to ListView

findViewById(R.id.addButton).setOnClickListener(new View.OnClickListener() {

@Override
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

public void onClick(View v) {

EditText input = findViewById(R.id.inputText);

String newItem = input.getText().toString();

if (!newItem.isEmpty()) {

listViewItems.add(newItem);

listViewAdapter.notifyDataSetChanged();

input.setText("");

} else {

Toast.makeText(MainActivity.this, "Please enter an item",


Toast.LENGTH_SHORT).show();

});

// Remove item from ListView

findViewById(R.id.removeButton).setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

if (selectedItemPosition >= 0 && selectedItemPosition < listViewItems.size()) {

listViewItems.remove(selectedItemPosition);

listViewAdapter.notifyDataSetChanged();

selectedItemPosition = -1; // Reset position after removal

} else {

Toast.makeText(MainActivity.this, "No item selected to remove",


Toast.LENGTH_SHORT).show();

}
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

});

// Update item in ListView

findViewById(R.id.updateButton).setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

EditText input = findViewById(R.id.inputText);

String updatedItem = input.getText().toString();

if (!updatedItem.isEmpty() && selectedItemPosition >= 0 && selectedItemPosition <


listViewItems.size()) {

listViewItems.set(selectedItemPosition, updatedItem);

listViewAdapter.notifyDataSetChanged();

input.setText("");

selectedItemPosition = -1; // Reset position after update

} else {

Toast.makeText(MainActivity.this, "No item selected or invalid input",


Toast.LENGTH_SHORT).show();

});

// Handle ListView item click

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

selectedItemPosition = position;
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Toast.makeText(MainActivity.this, "Selected: " + listViewItems.get(position),


Toast.LENGTH_SHORT).show();

} });

spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

@Override

public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

Toast.makeText(MainActivity.this, "Spinner Selected: " +


spinnerAdapter.getItem(position), Toast.LENGTH_SHORT).show();

@Override

public void onNothingSelected(AdapterView<?> parent) {

// No action needed

});

}
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Practical - 12
Aim :- Develop the code to manage Permission using Manifest file
and run time from Activity, and toggle state of WiFi and Bluetooth.

MAINACTIVITY.XML:
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:padding="16dp">

<Button

android:id="@+id/toggleWifiButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="WiFi" />

<Button

android:id="@+id/toggleBluetoothButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Bluetooth"

android:layout_below="@id/toggleWifiButton"

android:layout_marginTop="16dp" /> </RelativeLayout>


Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

MAINACTIVITY.JAVA:
package com.example.sample;

import androidx.appcompat.app.AppCompatActivity;

import androidx.core.app.ActivityCompat;

import androidx.core.content.ContextCompat;

import android.bluetooth.BluetoothAdapter;

import android.content.pm.PackageManager;

import android.os.Bundle;

import android.widget.Button;

import android.widget.Toast;

import androidx.annotation.NonNull;

import android.content.Intent;

import android.provider.Settings;

import android.Manifest;

public class MainActivity extends AppCompatActivity

private static final int PERMISSION_REQUEST_CODE = 100;

private Button openWifiSettingsButton;

private Button toggleBluetoothButton;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

openWifiSettingsButton = findViewById(R.id.toggleWifiButton);

toggleBluetoothButton = findViewById(R.id.toggleBluetoothButton);
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

if (checkPermissions()) {

initialize();

} else {

requestPermissions();

private boolean checkPermissions() {

return ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH) ==


PackageManager.PERMISSION_GRANTED

&&ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_ADMIN) ==
PackageManager.PERMISSION_GRANTED
&&ContextCompat.checkSelfPermission(this,Manifest.permission.BLUETOOTH_CONNECT)
== PackageManager.PERMISSION_GRANTED;

private void requestPermissions() {

ActivityCompat.requestPermissions(this,

new String[]{

Manifest.permission.BLUETOOTH,

Manifest.permission.BLUETOOTH_ADMIN,

Manifest.permission.BLUETOOTH_CONNECT,

Manifest.permission.BLUETOOTH_SCAN,

Manifest.permission.ACCESS_FINE_LOCATION

},

PERMISSION_REQUEST_CODE);

@Override
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,


@NonNull int[] grantResults) {

super.onRequestPermissionsResult(requestCode, permissions, grantResults);

if (requestCode == PERMISSION_REQUEST_CODE) {

if (grantResults.length > 0 && grantResults[0] ==


PackageManager.PERMISSION_GRANTED) {

initialize();

} else {

Toast.makeText(this, "Permissions are required for this app",


Toast.LENGTH_SHORT).show();

private void initialize() {

openWifiSettingsButton.setOnClickListener(v -> openWifiSettings());

toggleBluetoothButton.setOnClickListener(v -> toggleBluetooth());

private void openWifiSettings() {

Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);

startActivity(intent);

private void toggleBluetooth() {

if (checkPermissions()) {

try {

BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

if (bluetoothAdapter != null) {
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

boolean bluetoothEnabled = bluetoothAdapter.isEnabled();

if (bluetoothEnabled) {

bluetoothAdapter.disable();

Toast.makeText(this, "Bluetooth disabled", Toast.LENGTH_SHORT).show();

} else {

bluetoothAdapter.enable();

Toast.makeText(this, "Bluetooth enabled", Toast.LENGTH_SHORT).show();

} else {

Toast.makeText(this, "Bluetooth is not supported on this device",


Toast.LENGTH_SHORT).show();

} catch (SecurityException e) {

Toast.makeText(this, "Permission denied to modify Bluetooth state",


Toast.LENGTH_SHORT).show();

} else {

Toast.makeText(this, "Bluetooth permissions are required",


Toast.LENGTH_SHORT).show();

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">
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

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

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

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>

<intent-filter>

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

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

</intent-filter>

</activity>

</application>
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

<!-- Permissions for WiFi and Bluetooth -->

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

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

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

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

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

</manifest>
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Practical - 13
Aim :- Develop android applications to demonstrate user interaction
with the application using Options Menu, Context Menu and Popup
Menu.
Popup Menu.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<Button

android:id="@+id/clickBtn"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="#0F9D58"

android:text="Click Me"

android:textColor="#ffffff"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintLeft_toLeftOf="parent"
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

app:layout_constraintRight_toRightOf="parent"

app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

popup_menu.xml:
res→menu

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

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

<item

android:id="@+id/ml"

android:title="Machine Learning" />

<item

android:id="@+id/ai"

android:title="Artificial Intelligence" />

<item

android:id="@+id/android"

android:title="Android" />

<item

android:id="@+id/coa"

android:title="Computer Organization Architecture" />

</menu>

MainActivity.java:
package com.example.sample;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

import android.view.MenuItem;

import android.view.View;

import android.widget.Button;

import android.widget.PopupMenu;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

Button button;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

button = (Button) findViewById(R.id.clickBtn);

button.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

PopupMenu popupMenu = new PopupMenu(MainActivity.this, button);

popupMenu.getMenuInflater().inflate(R.menu.popup_menu, popupMenu.getMenu());

popupMenu.setOnMenuItemClickListener(new
PopupMenu.OnMenuItemClickListener() {

@Override

public boolean onMenuItemClick(MenuItem menuItem) {

Toast.makeText(MainActivity.this, "You Clicked " + menuItem.getTitle(),


Toast.LENGTH_SHORT).show();

return true;

});
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

// Showing the popup menu

popupMenu.show();

});

Context Menu
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

<!-- Relative Layout to display all the details -->

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/relLayout"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="#fff"

android:padding="16dp"

tools:context=".MainActivity">

<TextView

android:id="@+id/textView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:layout_marginTop="20dp"

android:text="Long press me!"

android:textColor="#000"

android:textSize="20sp"

android:textStyle="bold" />

</RelativeLayout>

MainActivity.java
package com.example.sample;

import android.graphics.Color;

import android.os.Bundle;

import android.view.ContextMenu;
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

import android.view.MenuItem;

import android.view.View;

import android.widget.RelativeLayout;

import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

TextView textView;

RelativeLayout relativeLayout;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

textView = (TextView) findViewById(R.id.textView);

relativeLayout = (RelativeLayout) findViewById(R.id.relLayout);

registerForContextMenu(textView);

@Override

public void onCreateContextMenu(ContextMenu menu, View v,


ContextMenu.ContextMenuInfo menuInfo) {

super.onCreateContextMenu(menu, v, menuInfo);

menu.setHeaderTitle("Choose a color");

menu.add(0, v.getId(), 0, "Yellow");

menu.add(0, v.getId(), 0, "Gray");

menu.add(0, v.getId(), 0, "Cyan");

}
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

@Override

public boolean onContextItemSelected(MenuItem item) {

if (item.getTitle() == "Yellow") {

relativeLayout.setBackgroundColor(Color.YELLOW);

} else if (item.getTitle() == "Gray") {

relativeLayout.setBackgroundColor(Color.GRAY);

} else if (item.getTitle() == "Cyan") {

relativeLayout.setBackgroundColor(Color.CYAN);

return true;

}
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Options Menu
Main_menu.xml:

<menu xmlns:app="http://schemas.android.com/apk/res-auto"

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

<item

android:id="@+id/action_settings"

android:title="Settings"

android:orderInCategory="100"

app:showAsAction="never" />

<item

android:id="@+id/action_about"

android:title="About"

android:orderInCategory="100"

app:showAsAction="never" />

</menu>

Activity_main.xml:

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Welcome to RMS!"
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

android:layout_centerInParent="true"

android:textSize="18sp" />

</RelativeLayout>

MainActivity.java
package com.example.sample;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main_menu, menu);

return true;

@Override

public boolean onOptionsItemSelected(MenuItem item) {

// Handle action bar item clicks here.


Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

int id = item.getItemId();

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

Toast.makeText(this, "Settings selected", Toast.LENGTH_SHORT).show();

return true;

} else if (id == R.id.action_about) {

Toast.makeText(this, "About selected", Toast.LENGTH_SHORT).show();

return true;

return super.onOptionsItemSelected(item);

}
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Practical - 14
Aim :- Develop Android Applications to demonstrate different
AlertDialogs and the Custom Dialog.

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:padding="16dp">

<Button

android:id="@+id/simple_dialog_button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Show Simple Dialog" />

<Button

android:id="@+id/confirmation_dialog_button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Show Confirmation Dialog"

android:layout_marginTop="16dp" />
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

<Button

android:id="@+id/input_dialog_button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Show Input Dialog"

android:layout_marginTop="16dp" />

<Button

android:id="@+id/custom_dialog_button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Show Custom Dialog"

android:layout_marginTop="16dp" />

</LinearLayout>

DIALOG_CUSTOM.XML:

TO CREATE NEW FILE:

RES–LAYOUT–LAYOUTRESOURCE FILE

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

android:layout_height="wrap_content"

android:orientation="vertical"

android:padding="16dp">

<TextView

android:id="@+id/custom_title"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Custom Dialog Title"

android:textSize="18sp"

android:textStyle="bold" />

<EditText

android:id="@+id/custom_input"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Enter something"

android:padding="16dp"/>

<Button

android:id="@+id/custom_positive_button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="OK"

android:layout_marginTop="16dp" />
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

<Button

android:id="@+id/custom_negative_button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Cancel"

android:layout_marginTop="8dp" />

</LinearLayout>

MAINACTIVITY.JAVA :
package com.example.krishnapr14;

import android.content.DialogInterface;

import android.os.Bundle;

import android.view.LayoutInflater;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

setContentView(R.layout.activity_main);

Button simpleDialogButton = findViewById(R.id.simple_dialog_button);

Button confirmationDialogButton = findViewById(R.id.confirmation_dialog_button);

Button inputDialogButton = findViewById(R.id.input_dialog_button);

Button customDialogButton = findViewById(R.id.custom_dialog_button);

simpleDialogButton.setOnClickListener(v -> showSimpleDialog());

confirmationDialogButton.setOnClickListener(v -> showConfirmationDialog());

inputDialogButton.setOnClickListener(v -> showInputDialog());

customDialogButton.setOnClickListener(v -> showCustomDialog());

private void showSimpleDialog() {

new AlertDialog.Builder(this)

.setTitle("Simple Dialog")

.setMessage("This is a simple AlertDialog.")

.setPositiveButton("OK", (dialog, which) -> Toast.makeText(MainActivity.this, "OK


Pressed", Toast.LENGTH_SHORT).show())

.show();

private void showConfirmationDialog() {

new AlertDialog.Builder(this)

.setTitle("Confirmation Dialog")

.setMessage("Are you sure you want to proceed?")

.setPositiveButton("Yes", (dialog, which) -> Toast.makeText(MainActivity.this, "Yes


Pressed", Toast.LENGTH_SHORT).show())

.setNegativeButton("No", (dialog, which) -> Toast.makeText(MainActivity.this, "No


Pressed", Toast.LENGTH_SHORT).show())
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

.show();

private void showInputDialog() {

final EditText input = new EditText(this);

new AlertDialog.Builder(this)

.setTitle("Input Dialog")

.setMessage("Please enter your input:")

.setView(input)

.setPositiveButton("Submit", (dialog, which) -> {

String userInput = input.getText().toString();

Toast.makeText(MainActivity.this, "Input: " + userInput,


Toast.LENGTH_SHORT).show();

})

.setNegativeButton("Cancel", (dialog, which) -> dialog.dismiss())

.show();

private void showCustomDialog() {

LayoutInflater inflater = getLayoutInflater();

View dialogView = inflater.inflate(R.layout.dialog_custom, null);

AlertDialog.Builder builder = new AlertDialog.Builder(this);

builder.setView(dialogView);

final EditText customInput = dialogView.findViewById(R.id.custom_input);

Button positiveButton = dialogView.findViewById(R.id.custom_positive_button);

Button negativeButton = dialogView.findViewById(R.id.custom_negative_button);


Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

AlertDialog dialog = builder.create();

positiveButton.setOnClickListener(v -> {

String inputText = customInput.getText().toString();

Toast.makeText(MainActivity.this, "Custom Input: " + inputText,


Toast.LENGTH_SHORT).show();

dialog.dismiss();

});

negativeButton.setOnClickListener(v -> dialog.dismiss());

dialog.show();

}
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

PRACTICAL 15
AIM : Develop Android Application for local database connectivity
and performing basic database operations (select, insert, update,
delete) using SQLiteDatabase and SQLiteOpenHelper Classes.
DatabaseHelper.java
package com.example.krishnapr15;

import android.content.ContentValues;

import android.content.Context;

import android.database.Cursor;

import android.database.sqlite.SQLiteDatabase;

import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {

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

private static final int DATABASE_VERSION = 1;

private static final String TABLE_NAME = "mytable";

private static final String COLUMN_ID = "id";

private static final String COLUMN_NAME = "name";

public DatabaseHelper(Context context) {

super(context, DATABASE_NAME, null, DATABASE_VERSION);

@Override

public void onCreate(SQLiteDatabase db) {

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

COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +

COLUMN_NAME + " TEXT)";


Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

db.execSQL(createTable);

@Override

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

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

onCreate(db);

public void insertData(String name) {

SQLiteDatabase db = this.getWritableDatabase();

ContentValues values = new ContentValues();

values.put(COLUMN_NAME, name);

db.insert(TABLE_NAME, null, values);

db.close();

public Cursor getData() {

SQLiteDatabase db = this.getReadableDatabase();

return db.rawQuery("SELECT * FROM " + TABLE_NAME, null);

public boolean updateData(int id, String name) {

SQLiteDatabase db = this.getWritableDatabase();

ContentValues values = new ContentValues();

values.put(COLUMN_NAME, name);

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


String[]{String.valueOf(id)});

db.close();
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

return result > 0; // Returns true if update was successful

public boolean deleteData(int id) {

SQLiteDatabase db = this.getWritableDatabase();

int result = db.delete(TABLE_NAME, COLUMN_ID + " = ?", new


String[]{String.valueOf(id)});

db.close();

return result > 0; // Returns true if delete was successful

MainActivity.java :
package com.example.krishnapr15;

import android.database.Cursor;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

DatabaseHelper db;

EditText nameInput, idInput;

TextView displayData;

@Override
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

db = new DatabaseHelper(this);

nameInput = findViewById(R.id.nameInput);

idInput = findViewById(R.id.idInput);

displayData = findViewById(R.id.displayData);

Button btnInsert = findViewById(R.id.btnInsert);

Button btnSelect = findViewById(R.id.btnSelect);

Button btnUpdate = findViewById(R.id.btnUpdate);

Button btnDelete = findViewById(R.id.btnDelete);

btnInsert.setOnClickListener(v -> {

String name = nameInput.getText().toString();

if (!name.isEmpty()) {

db.insertData(name);

Toast.makeText(this, "Data Inserted", Toast.LENGTH_SHORT).show();

nameInput.setText(""); // Clear input

} else {

Toast.makeText(this, "Please enter a name", Toast.LENGTH_SHORT).show();

});

btnSelect.setOnClickListener(v -> {

Cursor cursor = db.getData();

StringBuilder stringBuilder = new StringBuilder();

while (cursor.moveToNext()) {
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

int id = cursor.getInt(0);

String name = cursor.getString(1);

stringBuilder.append("ID:").append(id).append(",Name:").append(name).append("\n");

displayData.setText(stringBuilder.toString());

cursor.close(); // Close cursor to avoid memory leaks

});

btnUpdate.setOnClickListener(v -> {

String idStr = idInput.getText().toString();

String name = nameInput.getText().toString();

if (!idStr.isEmpty() && !name.isEmpty()) {

int id = Integer.parseInt(idStr);

boolean isUpdated = db.updateData(id, name);

if (isUpdated) {

Toast.makeText(this, "Data Updated", Toast.LENGTH_SHORT).show();

} else {

Toast.makeText(this,"Update failed,ID not found",


Toast.LENGTH_SHORT).show();

idInput.setText(""); // Clear input

nameInput.setText(""); // Clear input

} else {

Toast.makeText(this, "Please enter ID and name", Toast.LENGTH_SHORT).show();

});
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

btnDelete.setOnClickListener(v -> {

String idStr = idInput.getText().toString();

if (!idStr.isEmpty()) {

int id = Integer.parseInt(idStr);

boolean isDeleted = db.deleteData(id);

if (isDeleted) {

Toast.makeText(this, "Data Deleted", Toast.LENGTH_SHORT).show();

} else {

Toast.makeText(this, "Delete failed, ID not found",


Toast.LENGTH_SHORT).show();

idInput.setText(""); // Clear input

} else {

Toast.makeText(this, "Please enter ID to delete", Toast.LENGTH_SHORT).show();

});

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">
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

<EditText

android:id="@+id/nameInput"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Enter Name"

android:minHeight="48dp" />

<EditText

android:id="@+id/idInput"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Enter ID for Update/Delete"

android:minHeight="48dp" />

<Button

android:id="@+id/btnInsert"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Insert" />

<Button

android:id="@+id/btnSelect"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Select" />

<Button

android:id="@+id/btnUpdate"

android:layout_width="match_parent"
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

android:layout_height="wrap_content"

android:text="Update" />

<Button

android:id="@+id/btnDelete"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Delete" />

<TextView

android:id="@+id/displayData"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:textSize="16sp"

android:paddingTop="16dp"

android:text="Data will be displayed here" />

</LinearLayout>
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Insert:

Update :
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Delete :
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

PRACTICAL 16
AIM : Develop an Android Application to demonstrate the use of
RecyclerView and CardView for displaying list of items with multiple
information.

build.gradle (app) file


dependencies {

implementation 'androidx.cardview:cardview:1.0.0'

implementation 'androidx.recyclerview:recyclerview:1.2.1'

// Other dependencies...

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

<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_margin="8dp"

app:cardElevation="4dp"

app:cardCornerRadius="8dp">

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

android:padding="16dp">
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

<TextView

android:id="@+id/itemTitle"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textSize="20sp"

android:textStyle="bold"/>

<TextView

android:id="@+id/itemDescription"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textSize="16sp"/>

<TextView

android:id="@+id/itemDate"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textSize="14sp"

android:textColor="#888888"/>

</LinearLayout>

</androidx.cardview.widget.CardView>

ItemAdapter.java
package com.example.krishnapr16;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

import android.widget.TextView;

import androidx.annotation.NonNull;

import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class ItemAdapter extends RecyclerView.Adapter<ItemAdapter.ItemViewHolder> {

private List<Item> itemList;

public ItemAdapter(List<Item> itemList) {

this.itemList = itemList;

public static class ItemViewHolder extends RecyclerView.ViewHolder {

public TextView title;

public TextView description;

public TextView date;

public ItemViewHolder(View itemView) {

super(itemView);

title = itemView.findViewById(R.id.itemTitle);

description = itemView.findViewById(R.id.itemDescription);

date = itemView.findViewById(R.id.itemDate);

@NonNull

@Override

public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_card, parent,


false);
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

return new ItemViewHolder(view);

@Override

public void onBindViewHolder(@NonNull ItemViewHolder holder, int position) {

Item currentItem = itemList.get(position);

holder.title.setText(currentItem.getTitle());

holder.description.setText(currentItem.getDescription());

holder.date.setText(currentItem.getDate());

@Override

public int getItemCount() {

return itemList.size();

Item.java
package com.example.krishnapr16;

public class Item {

private String title;

private String description;

private String date;

public Item(String title, String description, String date) {

this.title = title;

this.description = description;

this.date = date;
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

public String getTitle() {

return title;

public String getDescription() {

return description;

public String getDate() {

return date;

MainActivity.java
package com.example.krishnapr16;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import androidx.recyclerview.widget.LinearLayoutManager;

import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;

import java.util.List;

public class MainActivity extends AppCompatActivity {

private RecyclerView recyclerView;

private ItemAdapter itemAdapter;

@Override
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

List<Item> itemList = new ArrayList<>();

for (int i = 0; i < 20; i++) {

itemList.add(new Item("Item Title " + (i + 1), "This is a description for item " + (i + 1),
"Date: 2024-10-" + (i + 1)));

recyclerView = findViewById(R.id.recyclerView);

recyclerView.setLayoutManager(new LinearLayoutManager(this));

itemAdapter = new ItemAdapter(itemList);

recyclerView.setAdapter(itemAdapter);

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent">

<androidx.recyclerview.widget.RecyclerView

android:id="@+id/recyclerView"

android:layout_width="match_parent"

android:layout_height="match_parent"/>

</RelativeLayout>
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Practical - 17
Aim :- Develop a simple application to display “Hello ” using
Kotlin.
Main_Activity.xml:

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:padding="16dp">

<TextView

android:id="@+id/textView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textSize="24sp"

android:text="Hello World!"

android:layout_centerInParent="true"/>

</RelativeLayout>

Kotlin file :
package com.example.krishnapr17

import androidx.appcompat.app.AppCompatActivity

import android.os.Bundle

import android.widget.TextView

class MainActivity : AppCompatActivity() {


Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)

setContentView(R.layout.activity_main)

// Get the application name from the resources

val appName = getString(R.string.app_name)

// Find the TextView by ID

val textView: TextView = findViewById(R.id.textView)

// Set the text to "Hello <Application Name>"

textView.text = "Hello RMS"

}
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Practical - 18
Aim :- Develop an android application using Kotlin having a
Button “Click” and upon clicking on that Button a Toast message
“Button Clicked” should be displayed on screen through Toast
Message.
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent">

<Button

android:id="@+id/button_click"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Click"

android:layout_centerInParent="true"/>

</RelativeLayout>

MainActivity.kt:
package com.example.krishnapr18;

import android.os.Bundle

import android.widget.Button

import android.widget.Toast

import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {


Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

super.onCreate(savedInstanceState)

setContentView(R.layout.activity_main)

val buttonClick: Button = findViewById(R.id.button_click)

buttonClick.setOnClickListener {

Toast.makeText(this, "Button Clicked", Toast.LENGTH_SHORT).show()

}
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Practical - 19
Aim : Publish an Android Application on Play Store.
Step 1 – Google Play Console Developer Account.
One of the primary steps of publishing an Android application on the Play Store is creating a
Google developer account on the Google Play Console. Google Play Console can be understood
as a backend operating system for all the apps published on the Play Store. Developers who intend
to publish an app on the Play Store must create a developer account on the console and pay a one-
time fee of $25, payable using a credit card or through online banking methods. Also, remember
that post submission, the developer account can take up to 48-hours to activate.

You’d have to sign in using your Gmail IDs as soon as you enter the console. Post your sign-in;
the Google Play Console will enquire whether an individual developer or organization will own
the app account. And, based on the ownership, you will enter basic information about yourself or
your organization which will lead to the payment section and the final account creation.

Finally, ensure you fill out all the credentials asked while creating the account.
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Step 2 – Set-up up a Google Merchant Account.


If your app involves in-app purchases, the next essential step is to link your developer account
with your merchant account. If you already have an existing merchant account, you can navigate
to Download reports and select Financial. However, to access this page, you must create a Google
Merchant Account.

And to create one, click on setup up a merchant account.


Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Once you create your new merchant account, it will automatically get linked to your Google Play
Console account and enable you to monitor, manage, and analyze the app sales and generate
reports.

Step 3 – Create Application


Once the merchant account is linked to your Google Play Console, the next step is to create an
application. And for creating an application, there are a few essential steps that you need to follow:

• Click on – Menu > All applications

• Select the ‘Create Application’ option.

Next, the play console will ask you to enter some basic app details. For instance,

• App Name – You must enter a 30-character long name in this field which will be displayed
on the Google Play Console. However, this app name can be changed afterward.
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

• Default language – Another essential field is the setup of the app language. You can
navigate to the drop-down menu and set a default language for your app.

• App or game – The next step is to define whether you upload an app or a game, but this
can again be revised afterward from the store settings.

• Free or paid – Define whether your app will be available free of cost or will require the
user to pay for it. The free or paid section can be updated from the Paid app page later, but
only until you publish your app. Once the app is live, you cannot transform your app from
free to paid

Once all of the above information is filled and verified, the Google Play Console will enquire for
affirmations from you. Ensure that your app matches the Google policies of the Developer Program
and Accepts US export laws. As soon as you agree to the terms and conditions, click Create App.

Step 4. App Store Listing Details


The next step to uploading the app on the Google Play console is filling in the essential information
regarding the application listing. Once you click on the ‘Create App,’ the Play Console will
automatically take you to a consolidated dashboard wherein you’ll have to enter the necessary
details to set up your app.
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

The Google Play Console will enquire about the following:

App name – As you have already entered the app name in the previous step, you need not enter
the same name again; however, if you wish to revise the title, this is where you can change the
name.

• Short description – This field requires you to enter an 80-character-long description that
best describes your app.

• Full description – The following field to the short description enables you to explain your
app in detail. You can expand the word limit to 4000 characters and leverage your targeted
keywords to lead Google to share your app with the relevant audience.
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Once all this information is added to the Google console, the next step is adding the app graphics,
category of the app, and the privacy policy. Remember, we asked you to keep high-quality images
ready before beginning the app publishing process; this is precisely where all those images will be
leveraged.

Further, here are the details you would require:

Once you are done uploading details, Hit the Save button.

Step 5 – Content Rating


Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

The next most crucial step is the content rating questionnaire. Without rating your app’s content,
Google will consider it an Underrated app and will certainly remove it from Google Play Store.
And since you might not want it, let’s learn the steps of adding a content rating.

To add the content rating, you’ll have to navigate to the main dashboard, set up your app, and
select the Content rating option.

The Next dashboard will pop up, and you’ll be able to navigate the “Start Questionnaire” button;
you have to click the tab and get started.

You’ll have to enter basic information about your app in the content rating section. This section is
divided into three sub-sections – Categories, Questionnaire, and Summary.

In the Category section, you have to enter the email address that the users can leverage to contact
you and the category of the app you are publishing on the Play Store.
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Once you are done filing the above fields, click the Next button, and you’ll be redirected to the
questionnaire section. The questionnaire section lets Google explore more about your app to
understand your target audience better.

Once all the details are filled in, you can look at the content rating summary and hit ‘Submit’ to
apply the changes.

Step 6 – Create & Upload Android App to Google Play


Uploading the APK to the Google Play Console is the foremost step of the app publishing process,
where the app is finally uploaded and submitted for Google to review and go live.

But before we go and upload the app, one crucial decision you need to make is the type of app
release – Internal Test (available for up to 100 testers that you pick), Close Test (available to just
a specific number of testers), Production Release (available to all the Play store users in your
chosen countries), or Open Test (available to Google Playtesters, and users to join tests from your
store listing).
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083

Once you have decided on the testing, you can go to the dashboard and select “Create a new
release.

Post selecting “Create a new release,” you’ll be redirected to a dashboard, wherein you will upload
the app bundles and the release details.

You might also like