Android - Practicals H.
Android - Practicals H.
Practical -1
Aim : Set-up of Android development environment, managing AVD and
understanding its various components.
To setup an environment for the Android application development, you will need to
download and install the following :
➢ 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.
➢ 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.
➢ 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
➢ 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
If you don't see the hardware profile you want, than you
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.
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:
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:
<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: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;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lifecycleEventsTextView = findViewById(R.id.lifecycleEventsTextView);
logLifecycleEvent("onCreate");
@Override
super.onStart();
logLifecycleEvent("onStart");
@Override
super.onResume();
logLifecycleEvent("onResume");
@Override
super.onPause();
logLifecycleEvent("onPause");
@Override
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083
super.onStop();
logLifecycleEvent("onStop");
@Override
super.onRestart();
logLifecycleEvent("onRestart");
@Override
super.onDestroy();
logLifecycleEvent("onDestroy");
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
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.
<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"
<Button
android:id="@+id/btnSubmit"
android:layout_width="wrap_content"
</LinearLayout>
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083
<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
<RadioButton android:id="@+id/radioOption1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/chkSound"
<RadioButton android:id="@+id/radioOption2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/radioOption1"
<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
<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
<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.
<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;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.text_view);
}
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.
<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: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: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: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;
RadioGroup radioGroup;
RadioButton selectedRadioButton;
Button buttonSubmit;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonSubmit = findViewById(R.id.btnSubmit);
radioGroup = findViewById(R.id.radioGroup);
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083
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
selectedRadioButton = findViewById(radioGroup.getCheckedRadioButtonId());
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");
Toast.makeText(MainActivity.this,
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;
@Override
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
sendData();
});
name = nameText.getText().toString().trim();
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083
age = ageText.getText().toString().trim();
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;
@Override
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);
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;
SharedPreferences sharedpreferences;
TextView name;
TextView email;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
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, ""));
} }
String n = name.getText().toString();
String e = email.getText().toString();
editor.putString(Name, n);
editor.putString(Email, e);
editor.commit(); }
name.setText("");
email.setText("");
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
// 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"
<Button
android:id="@+id/addButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<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;
@Override
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = findViewById(R.id.listView);
spinner = findViewById(R.id.spinner);
listView.setAdapter(listViewAdapter);
spinnerItems.add("Item 1");
spinnerItems.add("Item 2");
spinnerItems.add("Item 3");
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(spinnerAdapter);
findViewById(R.id.addButton).setOnClickListener(new View.OnClickListener() {
@Override
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083
if (!newItem.isEmpty()) {
listViewItems.add(newItem);
listViewAdapter.notifyDataSetChanged();
input.setText("");
} else {
});
findViewById(R.id.removeButton).setOnClickListener(new View.OnClickListener() {
@Override
listViewItems.remove(selectedItemPosition);
listViewAdapter.notifyDataSetChanged();
} else {
}
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083
});
findViewById(R.id.updateButton).setOnClickListener(new View.OnClickListener() {
@Override
listViewItems.set(selectedItemPosition, updatedItem);
listViewAdapter.notifyDataSetChanged();
input.setText("");
} else {
});
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
} });
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
@Override
// 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"
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;
@Override
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();
&&ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_ADMIN) ==
PackageManager.PERMISSION_GRANTED
&&ContextCompat.checkSelfPermission(this,Manifest.permission.BLUETOOTH_CONNECT)
== PackageManager.PERMISSION_GRANTED;
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
if (requestCode == PERMISSION_REQUEST_CODE) {
initialize();
} else {
startActivity(intent);
if (checkPermissions()) {
try {
if (bluetoothAdapter != null) {
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083
if (bluetoothEnabled) {
bluetoothAdapter.disable();
} else {
bluetoothAdapter.enable();
} else {
} catch (SecurityException e) {
} else {
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
<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>
</intent-filter>
<intent-filter>
</intent-filter>
</activity>
</application>
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083
</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
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/ml"
<item
android:id="@+id/ai"
<item
android:id="@+id/android"
android:title="Android" />
<item
android:id="@+id/coa"
</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;
Button button;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button.setOnClickListener(new View.OnClickListener() {
@Override
popupMenu.getMenuInflater().inflate(R.menu.popup_menu, popupMenu.getMenu());
popupMenu.setOnMenuItemClickListener(new
PopupMenu.OnMenuItemClickListener() {
@Override
return true;
});
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083
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
<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: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;
TextView textView;
RelativeLayout relativeLayout;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
registerForContextMenu(textView);
@Override
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Choose a color");
}
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083
@Override
if (item.getTitle() == "Yellow") {
relativeLayout.setBackgroundColor(Color.YELLOW);
relativeLayout.setBackgroundColor(Color.GRAY);
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:
<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;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@Override
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
@Override
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
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"
<Button
android:id="@+id/confirmation_dialog_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
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:layout_marginTop="16dp" />
<Button
android:id="@+id/custom_dialog_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp" />
</LinearLayout>
DIALOG_CUSTOM.XML:
RES–LAYOUT–LAYOUTRESOURCE FILE
<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: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;
@Override
super.onCreate(savedInstanceState);
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083
setContentView(R.layout.activity_main);
new AlertDialog.Builder(this)
.setTitle("Simple Dialog")
.show();
new AlertDialog.Builder(this)
.setTitle("Confirmation Dialog")
.show();
new AlertDialog.Builder(this)
.setTitle("Input Dialog")
.setView(input)
})
.show();
builder.setView(dialogView);
positiveButton.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;
@Override
db.execSQL(createTable);
@Override
onCreate(db);
SQLiteDatabase db = this.getWritableDatabase();
values.put(COLUMN_NAME, name);
db.close();
SQLiteDatabase db = this.getReadableDatabase();
SQLiteDatabase db = this.getWritableDatabase();
values.put(COLUMN_NAME, name);
db.close();
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083
SQLiteDatabase db = this.getWritableDatabase();
db.close();
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;
DatabaseHelper db;
TextView displayData;
@Override
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083
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);
btnInsert.setOnClickListener(v -> {
if (!name.isEmpty()) {
db.insertData(name);
} else {
});
btnSelect.setOnClickListener(v -> {
while (cursor.moveToNext()) {
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083
int id = cursor.getInt(0);
stringBuilder.append("ID:").append(id).append(",Name:").append(name).append("\n");
displayData.setText(stringBuilder.toString());
});
btnUpdate.setOnClickListener(v -> {
int id = Integer.parseInt(idStr);
if (isUpdated) {
} else {
} else {
});
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083
btnDelete.setOnClickListener(v -> {
if (!idStr.isEmpty()) {
int id = Integer.parseInt(idStr);
if (isDeleted) {
} else {
} else {
});
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: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"
</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.
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;
this.itemList = itemList;
super(itemView);
title = itemView.findViewById(R.id.itemTitle);
description = itemView.findViewById(R.id.itemDescription);
date = itemView.findViewById(R.id.itemDate);
@NonNull
@Override
@Override
holder.title.setText(currentItem.getTitle());
holder.description.setText(currentItem.getDescription());
holder.date.setText(currentItem.getDate());
@Override
return itemList.size();
Item.java
package com.example.krishnapr16;
this.title = title;
this.description = description;
this.date = date;
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083
return title;
return description;
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;
@Override
Subject: Mobile Application Development using Android Sub-Code: 4350703
En. No: 226420307083
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
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));
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:
<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
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
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
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
buttonClick.setOnClickListener {
}
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
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.
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.
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.
Once you are done uploading details, Hit the Save button.
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.
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.