18CSMP68 - Mobile Application Development
18CSMP68 - Mobile Application Development
18CSMP68 - Mobile Application Development
(2018
2018 CBCS Scheme)
As per VTU Revised Syllabus for VI Semester CSE
Name: ___________________________________________
USN: ____________________________________________
To impart quality education for producing world class engineers with latest knowledge and
innovative ideas in Computer Science & Engineering to meet the expectations of industry
and society and to produce globally competent graduates with moral values committed to
build a vibrant nation.
On completion of B.E Computer Science & Engineering Program, The graduates will
be able to -
PSO 1 The ability to understand, analyse and develop computer programs in the areas
related to algorithms, system software, multimedia, web design, big data
analytics, and networking for efficient design of computer-based systems of
varying complexity.
PSO 2 The ability to understand the evolutionary changes in computing, apply standard
practices and strategies in software project development using open-ended
programming environments to deliver a quality product for business success, real
world problems and meet the challenges of the future.
PSO 3 The ability to employ modern computer languages, environments, and platforms
in creating innovative career paths to be an entrepreneur, lifelong learning and a
zest for higher studies and also to act as a good citizen by inculcating in them
moral values & ethics.
In support of the mission, within few years of graduation, the Computer Science &
Engineering programme will enable its graduates to -
PEO 1 To be able to comprehend, understand and analyze Computer Science and
Engineering problems and relate them with real life.
PEO 2 To provide in depth knowledge to design and develop novel products and
innovative solution for real life problems in Computer Science and Engineering
field and related domains.
PEO 3 To inculcate a conviction to believe in self, impart professional and ethical
attitude, nurture to be an effective team member, infuse leadership qualities, build
proficiency in soft skills and the abilities to relate engineering with the social
issues.
PEO 4 To impart exhaustive knowledge of Computer Science & Engineering to take up
key assignments in industry, undertake and excel in higher studies and Research
& Development in computer science, related engineering fields and management.
PROGRAM OUTCOMES (POs)
PO 1: Engineering knowledge: Apply the knowledge of mathematics, science,
engineering fundamentals, and an engineering specialization to the solution of
complex engineering problems.
PO 2: Problem analysis: Identify, formulate, review research literature, and analyze
complex engineering problems reaching substantiated conclusions using first
principles of mathematics, natural sciences, and engineering sciences.
PO 3: Design/development of solutions: Design solutions for complex engineering
problems and design system components or processes that meet the specified needs
with appropriate consideration for the public health and safety, and the cultural,
societal, and environmental considerations.
PO 4: Conduct investigations of complex problems: Use research-based knowledge
and research methods including design of experiments, analysis and interpretation
of data, and synthesis of the information to provide validconclusions.
PO 5: Modern tool usage: Create, select, and apply appropriate techniques, resources,
and modern engineering and IT tools including prediction and modeling to
complex engineering activities with an understanding of the limitations.
PO 6: The engineer and society: Apply reasoning informed by the contextual
knowledge to assess societal, health, safety, legal and cultural issues and the
consequent responsibilities relevant to the professional engineeringpractice.
PO 7: Environment and sustainability: Understand the impact of the professional
engineering solutions in societal and environmental contexts, and demonstrate the
knowledge of, and need for sustainabledevelopment.
PO 8: Ethics: Apply ethical principles and commit to professional ethics and
responsibilities and norms of the engineering practice.
PO 9: Individual and team work: Function effectively as an individual, and as a
member or leader in diverse teams, and in multidisciplinary settings.
PO 10: Communication: Communicate effectively on complex engineering activities with
the engineering community and with society at large, such as, being able to
comprehend and write effective reports and design documentation, make effective
presentations, and give and receive clear instructions.
PO 11: Project management and finance: Demonstrate knowledge and understanding of
the engineering and management principles and apply these to one‟s own work, as
a memberand leader in a team, to manage projects and in
multidisciplinaryenvironments.
PO 12: Life-long learning: Recognize the need for, and have the preparation and ability to
engage in independent and life-long learning in the broadest context of
technological change.
SYLLABUS
MOBILE APPLICATION DEVELOPMENT
B.E, VI Semester, Computer Science & Engineering
[As per Choice Based Credit System (CBCS) scheme]
Course Code 18CSMP68 CIE Marks 40
Number of Contact 03 Hours/Week SEE Marks 60
Hours/Week
RBT Levels L1, L2, L3 Exam Hours 03
Credits – 02
Laboratory Objectives: This Laboratory – 18CSMP68, will enable students to
CO 1: To understand, Learn and acquire the art of Android Programming.
CO 2: To understand Configuring Android studio to run the applications.
CO 3: To understand and implement Android's User interface functions.
CO 4: To Create, modify and query on SQlite database.
CO 5: To Inspect different methods of sharing data using services.
Descriptions (if any)
1. The installation procedure of the Android Studio/Java software must be
demonstrated and carried out in groups.
2. Students should use the latest version of Android Studio/Java/Kotlin to execute
these programs. Diagrams given are for representational purpose only, students are
expected to improvise on them.
3. Part B programs should be developed as an application and are to be
demonstrated as a mini project in a group by adding extra features or the
students can also develop their application and demonstrate it as a mini
project (projects/programs are not limited to the list given in Part B)
PART A
1. Create an application to design a Visiting Card. The Visiting card should have a
company logo at the top right corner. The company name should be displayed in
Capital letters, aligned to the center. Information like the name of the employee, job
title, phone number, address, email, fax and the website address is to be displayed.
Insert a horizontal line between the job title and the phone number.
2. Develop an Android application using controls like Button, TextView, EditText for
designing a calculator having basic functionality like Addition, Subtraction,
Multiplication and Division.
3. Create a SIGN Up activity with Username and Password. Validation of password
should happen based on the following rules:
Password should contain uppercase and lowercase letters.
Password should contain letters and numbers.
Password should contain special characters.
· Minimum length of the password (the default value is 8).
On successful SIGN UP proceed to the next Login activity. Here the user should SIGN
IN using the Username and Password created during signup activity. If the Username and
Password are matched then navigate to the next activity which displays a message saying
“Successful Login” or else display a toast message saying “Login Failed”. The user is
given only two attempts and after that display a toast message saying “Failed Login
Attempts” and disable the SIGN IN button. Use Bundle to transfer information from one
activity to another.
6. Create two files of XML and JSON type with values for City, Name, Latitude,
Longitude, Temperature, and Humidity. Develop an application to create an activity
with two buttons to parse the XML and JSON files which when clicked should display
the data in their respective layouts side by side.
7. Develop a simple application withoneEditTextso that the user can write some text in
it. Create a button called “Convert Text to Speech” that converts the user input text
into voice.
8. Create an activity like a phone dialer withCALLand SAVE buttons. On pressing the
CALL button, it must call the phone number and on pressing the SAVE button it must
save the number to the phone contacts.
PART B
1. Write a program to enter Medicine Name, Date and Time of the Day as input from the
user and store it in the SQLite database. Input for Time of the Day should be either
Morning or Afternoon or Evening or Night. Trigger an alarm based on the Date and
Time of the Day and display the Medicine Name.
4. Write a program to create an activity having a Text box, and also Save, Open and
Create buttons. The user has to write some text in the Text box. On pressing the
Create button the text should be saved as a text file in MkSDcard. On subsequent
changes to the text, the Save button should be pressed to store the latest content to the
same file. On pressing the Open button, it should display the contents from the
previously stored files in the Text box. If the user tries to save the contents in the
Textbox to a file without creating it, then a toast message has to be displayed saying
“First Create a File”.
8. Create an AIDL service that calculates Car Loan EMI. The formula to calculate EMI
is
E = P * (r(1+r)n)/((1+r)n-1)
Where,
E = The EMI payable on the car loan amount
P = The Car loan Principal Amount
r = The interest rate value computed on a monthly basis
n = The loan tenure in the form of months
The down payment amount has to be deducted from the principal amount paid towards
buying the Car. Develop an application that makes use of this AIDL service to calculate
the EMI. This application should have four EditText to read the PrincipalAmount, Down
Payment, Interest Rate, Loan Term (in months) and a button named as “Calculate
Monthly EMI”. On click of this button, the result should be shown in a TextView. Also,
calculate the EMI by varying the Loan Term and Interest Rate values.
Laboratory Outcomes:After studying theselaboratory programs, students will be able to
Create, test and debug Android application by setting up Android development
environment.
Implement adaptive, responsive user interfaces that work across a wide range of
devices.
Infer long running tasks and background work in Android applications.
Demonstrate methods in storing, sharing and retrieving data in Android
applications.
Infer the role of permissions and security for Android applications.
Procedure to Conduct Practical Examination
Experiment distribution
o For laboratories having only one part: Students are allowed to pick one
experiment from the lot with equal opportunity.
o For laboratories having PART A and PART B: Students are allowed to
pick one experiment from PART A and one experiment from PART B,
with equal opportunity.
Change of experiment is allowed only once and marks allotted for procedure to be
made zero of the changed part only.
Marks Distribution (Courseed to change in accordance with university regulations)
o For laboratories having only one part – Procedure + Execution + Viva-
Voce:
15+70+15= 100 Marks
o For laboratories having PART A and PART B
i. Part A – Procedure + Execution + Viva = 6 + 28 + 6 = 40 Marks
ii. Part B – Procedure + Execution + Viva = 9 + 42 + 9 = 60 Marks
Text Books
Google Developer Training, "Android Developer Fundamentals Course – Concept
Reference”, Google Developer Training Team, 2017.
https://www.gitbook.com/book/google-developer-training/android-developerfundamentals-course-
concepts/details
(Download pdf file from the above link)
Reference Books
1. Erik Hellman, “Android Programming – Pushing the Limits”, 1st Edition, Wiley
India Pvt Ltd, 2014. ISBN-13: 978-8126547197
2. Dawn Griffiths and David Griffiths, “Head First Android Development”, 1st
Edition, O’Reilly SPD Publishers, 2015. ISBN-13: 978-9352131341
3. Bill Phillips, Chris Stewart and Kristin Marsicano, “Android Programming: The
Big Nerd Ranch Guide”, 3rd Edition, Big Nerd Ranch Guides, 2017. ISBN-13: 978-
0134706054
CONTENTS
Chapter - 01
ANDROID
Android is a mobile operating system based on a modified version of the Linux kernel
and other open source software, designed primarily for touch screen mobile devices such as
smart phones and tablets. Android is developed by a consortium of developers known as the
Open Handset Alliance, with the main contributor and commercial marketer being Google.
Initially developed by Android Inc., which Google bought in 2005, Android was unveiled in
2007, with the first commercial Android device launched in September 2008. The current
stable version is Android 11, released on September 8, 2020.
1.3 LIBRARIES
On top of Linux kernel there is a set of libraries including open -source Web browser
engine WebKit, well known library libc, SQLite database which is a useful repository for
storage and sharing of application data, libraries to play and record audio and video, SSL
libraries responsible for Internet security etc.
1.6 APPLICATIONS
You will find all the Android application at the top layer. You will write your
application to be installed on this layer only. Examples of such applications are Contacts
Books, Browser, and Games etc.
1.7 ANDROID UI
An Android application user interface is everything that the user can see and interact
with.
Chapter - 02
ANDROID STUDIO
Android Studio is the official Integrated Development Environment (IDE) for
Android app development, based on IntelliJ IDEA . On top of IntelliJ's powerful code editor
and developer tools, Android Studio offers even more features that enhance your productivity
when building Android apps, such as:
A flexible Gradle-based build system
A unified environment where you can develop for all Android devices
Apply Changes to push code and resource changes to your running app without
restarting your app
Code templates and GitHub integration to help you build common app features and
import sample code
Lint tools to catch performance, usability, version compatibility, and other problems
Built-in support for Google Cloud Platform, making it easy to integrate Google Cloud
Messaging and App Engine
Each project in Android Studio contains one or more modules with source code files and
resource files. Types of modules include:
Android app modules
Library modules
By default, Android Studio displays your project files in the Android project view, as
shown in Fig 2.1. This view is organized by modules to provide quick access to your project's
key source files.
All the build files are visible at the top level under Gradle Scripts and each app module
contains the following folders:
java: Contains the Java source code files, including JUnit test code.
res: Contains all non-code resources, such as XML layouts, UI strings, and bitmap
images.
The Android project structure on disk differs from this flattened representation. To see the
actual file structure of the project, select Project from the Project dropdown (in Fig 2.1, it's
showing as Android).
Program-1: Create an application to design a Visiting Card. The Visiting card should have a
company logo at the top right corner. The company name should be displayed in Capital
letters, aligned to the center. Information like the name of the employee, job title, phone
number, address, email, fax and the website address is to be displayed. Insert a horizontal line
between the job title and the phone number.
XML CODE
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="17dp"
android:layout_marginLeft="17dp"
android:layout_marginTop="17dp"
android:layout_marginEnd="244dp"
android:layout_marginRight="244dp"
android:layout_marginBottom="486dp"
android:text="MITT"
android:textSize="38dp" />
<ImageView
android:id="@+id/imageView"
android:layout_width="231dp"
android:layout_height="174dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-14dp"
android:layout_marginRight="-14dp"
android:layout_marginBottom="481dp"
app:srcCompat="@drawable/logo" />
<View
android:id="@+id/view"
android:layout_width="wrap_content"
android:layout_height="4dp"
android:layout_alignParentBottom="true"
android:background="#4444"
android:layout_marginBottom="466dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="117dp"
android:layout_marginRight="117dp"
android:layout_marginBottom="394dp"
android:text="N N Naveen"
android:textSize="30dp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="64dp"
android:layout_marginRight="64dp"
android:layout_marginBottom="343dp"
android:text="Assistant Professor-CSE"
android:textSize="25dp" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="127dp"
android:layout_marginRight="127dp"
android:layout_marginBottom="294dp"
android:text="Ph No: 9036915739"
android:textSize="20dp" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="229dp"
android:text="#6273, Sri Krishna Dhama, 2nd Phase, 4th Stage
Vijaya Nagar, Mysuru-17"
android:textSize="20dp" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="44dp"
android:layout_marginRight="44dp"
android:layout_marginBottom="189dp"
android:text="Email: [email protected]"
android:textSize="20dp" />
</RelativeLayout>
JAVA-CODE
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
OUTPUT
Program-2: Develop an Android application using controls like Button, TextView, EditText
for designing a calculator having basic functionality like Addition, Subtraction,
Multiplication, and Division.
6. Add TextView component to display result & change the following properties:
Size: 40dp
Text: “0”
Center-Align
id: “@+id/textView1”
7. Add 4 Buttons & rename the four buttons “Add”, “Sub”, ”Mul” and “Div” with
following addition:
Onclick: “doAdd”(Add Button)
Onclick: “doSub”(Sub Button)
Onclick: “doMul”(Mul Button)
Onclick: “doDiv”(Div Button)
XML CODE
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="98dp"
android:layout_marginBottom="653dp"
android:text="SIMPLE CALCULATOR"
android:textSize="32dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.042" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="115dp"
android:layout_marginBottom="547dp"
android:ems="10"
android:hint="Enter the First Number"
android:inputType="textPersonName"
android:text="" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="111dp"
android:layout_marginBottom="455dp"
android:ems="10"
android:inputType="textPersonName"
android:hint="Enter the Second Number"
android:text="" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="203dp"
android:layout_marginBottom="350dp"
android:text="0"
android:textSize="40dp" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="274dp"
android:layout_marginBottom="237dp"
android:onClick="doAdd"
android:text="ADD" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="68dp"
android:layout_marginBottom="233dp"
android:onClick="doSub"
android:text="SUB" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="277dp"
android:layout_marginBottom="115dp"
android:onClick="doMul"
android:text="MUL" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="63dp"
android:layout_marginBottom="104dp"
android:onClick="doDiv"
android:text="DIV" />
</RelativeLayout>
JAVA CODE
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
OUTPUT
XML CODE
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:layout_width="160dp"
android:layout_height="42dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="112dp"
android:layout_marginBottom="573dp"
android:text="Sign Up"
android:textSize="28dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/emailEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="29dp"
android:layout_marginBottom="431dp"
android:ems="10"
android:hint="Email ID"
android:inputType="textEmailAddress"
android:textSize="28dp" />
<EditText
android:id="@+id/passwordEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="34dp"
android:layout_marginBottom="345dp"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
android:textSize="28dp" />
<Button
android:id="@+id/signUpBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="106dp"
android:layout_marginBottom="226dp"
android:text="Sign Up"
android:textSize="28dp" />
</RelativeLayout>
JAVA CODE
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.util.regex.Pattern;
public class MainActivity extends AppCompatActivity {
EditText emailEditText, passwordEditText;
Button signUpBtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
emailEditText = findViewById(R.id.emailEditText);
passwordEditText = findViewById(R.id.passwordEditText);
signUpBtn = findViewById(R.id.signUpBtn);
signUpBtn.setOnClickListener(new View.OnClickListener() {
@Override
<TextView
android:id="@+id/textView"
android:layout_width="210dp"
android:layout_height="54dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="120dp"
android:layout_marginBottom="576dp"
android:text="Login Activity"
android:textSize="28dp" />
<EditText
android:id="@+id/emailEditText"
android:layout_width="363dp"
android:layout_height="83dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="27dp"
android:layout_marginBottom="419dp"
android:ems="10"
android:hint="Email ID"
android:inputType="textEmailAddress"
android:textSize="28dp" />
<EditText
android:id="@+id/passwordEditText"
android:layout_width="354dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="40dp"
android:layout_marginBottom="299dp"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
android:textSize="28dp" />
<Button
android:id="@+id/loginBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="173dp"
android:layout_marginBottom="189dp"
android:text="login"
android:textSize="26dp" />
</RelativeLayout>
JAVA CODE
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class LoginActivity extends AppCompatActivity {
EditText emailEditText, passwordEditText;
Button loginBtn;
int counter=2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
emailEditText=findViewById(R.id.emailEditText);
passwordEditText=findViewById(R.id.passwordEditText);
loginBtn=findViewById(R.id.loginBtn);
String registeredEmail=getIntent().getStringExtra("email");
String
registeredPassword=getIntent().getStringExtra("password");
loginBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String email=emailEditText.getText().toString();
String
password=passwordEditText.getText().toString();
if(registeredEmail.equals(email)&&
registeredPassword.equals(password))
{
Intent intent=new
Intent(LoginActivity.this,LoginSuccessful.class);
startActivity(intent);
}
else{
Toast.makeText(LoginActivity.this,"InvalidCredentials",Toast.LENGTH_
LONG).show();
}
counter--;
if (counter==0)
{
Toast.makeText(getBaseContext(),"FAILED LOGIN
ATTEMPTS",Toast.LENGTH_LONG).show();
loginBtn.setEnabled(false);
}
}
});
}
}
<TextView
android:id="@+id/textView2"
android:layout_width="297dp"
android:layout_height="190dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="42dp"
android:layout_marginBottom="400dp"
android:text="Login Successful"
android:textSize="38dp" />
</RelativeLayout>
JAVA CODE
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
OUTPUT
<TextView
android:id="@+id/textView"
android:layout_width="243dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="73dp"
android:layout_marginBottom="559dp"
android:text="Wall Paper Change Application"
android:textAlignment="center"
android:textSize="28dp" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-13dp"
android:layout_marginBottom="177dp"
android:text="Click Here To Change Wall Paper"
android:textSize="26dp" />
</RelativeLayout>
JAVA CODE
import androidx.appcompat.app.AppCompatActivity;
import android.app.WallpaperManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
setWallpaper();
}
});
}
private void setWallpaper() {
mytimer.schedule(new TimerTask() {
@Override
public void run() {
if(prev==1) {
drawable =
getResources().getDrawable(R.drawable.one);
prev = 2;
}
else if(prev==2) {
drawable =
getResources().getDrawable(R.drawable.two);
prev=3;
}
else if(prev==3) {
drawable =
getResources().getDrawable(R.drawable.three);
prev=4;
}
else if(prev==4) {
drawable =
getResources().getDrawable(R.drawable.four);
prev=5;
}
else if(prev==5) {
drawable =
getResources().getDrawable(R.drawable.five);
prev=1;
}
Bitmap wallpaper =
((BitmapDrawable)drawable).getBitmap();
try {
wpm.setBitmap(wallpaper);
} catch (IOException e) {
e.printStackTrace();
}
}
},0,30000); } }
OUTPUT
Program-5: Write a program to create an activity with two buttons START and STOP. On
pressing of the START button, the activity must start the counter by displaying the numbers
from One and the counter must keep on counting until the STOP button is pressed. Display
the counter value in a TextViewcontrol.
XML CODE
<TextView
android:layout_width="378dp"
android:layout_height="68dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="18dp"
android:layout_marginBottom="602dp"
android:text="Counter Application"
android:textSize="38dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView"
android:layout_width="121dp"
android:layout_height="32dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="145dp"
android:layout_marginBottom="478dp"
android:text="Counter Value" />
<Button
android:id="@+id/btn_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="234dp"
android:layout_marginBottom="296dp"
android:text="Start" />
<Button
android:id="@+id/btn_stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="73dp"
android:layout_marginBottom="295dp"
android:text="Stop" />
</RelativeLayout>
JAVA CODE
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
Button btnstart, btnstop;
TextView txtcounter;
int i=1;
Handler customHandler=new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnstart=findViewById(R.id.btn_start);
btnstop=findViewById(R.id.btn_stop);
txtcounter=findViewById(R.id.textView);
btnstart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
customHandler.postDelayed(updateTimerThread,0);
}
});
btnstop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
customHandler.removeCallbacks(updateTimerThread);
}
});
}
private final Runnable updateTimerThread=new Runnable() {
@Override
public void run() {
txtcounter.setText(""+i);
customHandler.postDelayed(this,1000);
i++;
}
};
}
OUTPUT
Program-6: Create two files of XML and JSON type with values for City_Name, Latitude,
Longitude, Temperature, and Humidity. Develop an application to create an activity with two
buttons to parse the XML and JSON files which when clicked should display the data in their
respective layouts side by side.
city.xml
<?xml version="1.0"?>
<records>
<place>
<name>Mysore</name>
<lat>12.295</lat>
<long>76.639</long>
<temperature>22</temperature>
<humidity>90 %</humidity>
</place>
<place>
<name>Bangalore</name>
<lat>12.97165</lat>
<long>77.5946</long>
<temperature>25</temperature>
<humidity>74 %</humidity>
</place>
</records>
city.json
[
{
"name": "HASSAN",
"lat": "12.295",
"long": "76.639",
"temperature": "22",
"humidity": "92 %"
},
{
"name": "MANDYA",
"lat": "12.97165",
"long": "77.5946",
"temperature": "25",
"humidity": "74 %"
}
]
XML CODE
<TextView
android:id="@+id/textView"
android:layout_width="292dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="57dp"
android:layout_marginBottom="597dp"
android:text="Parsing XML and JSON"
android:textAlignment="center"
android:textSize="26dp" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="116dp"
android:layout_marginBottom="486dp"
android:onClick="parsexml"
android:text="ParseXML" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="116dp"
android:layout_marginBottom="366dp"
android:onClick="parsejson"
android:text="ParseJSON" />
<TextView
android:id="@+id/display"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="3dp"
android:layout_marginBottom="68dp"
android:text=""
android:textAlignment="center" />
</RelativeLayout>
JAVA CODE
import android.os.Build;
import android.os.Bundle;
import android.text.style.TabStopSpan;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import org.json.JSONArray;
import org.json.JSONObject;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
").append(jsonObject.getString("lat"));
stringBuilder.append("\nLongitude:
").append(jsonObject.getString("long"));
stringBuilder.append("\nTemperature:
").append(jsonObject.getString("temperature"));
stringBuilder.append("\nHumidity:
").append(jsonObject.getString("humidity"));
stringBuilder.append("\n----------");
}
display.setText(stringBuilder.toString());
is.close();
}
catch (Exception e){
e.printStackTrace();
Toast.makeText(MainActivity.this,"Error in
reading",Toast.LENGTH_LONG).show();
}
}
private String getValue(String tag, Element element)
{
return
element.getElementsByTagName(tag).item(0).getChildNodes().item(0).ge
tNodeValue();
}
}
OUTPUT
Program-7: Develop a simple application with one EditText so that the user can write some
text in it. Create a button called “Convert Text to Speech” that converts the user input text
into voice.
XML CODE
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="59dp"
android:layout_marginRight="59dp"
android:layout_marginBottom="649dp"
android:text="Text2SpeechApp"
android:textSize="40dp" />
<EditText
android:id="@+id/editText"
android:layout_width="264dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="78dp"
android:layout_marginRight="78dp"
android:layout_marginBottom="505dp"
android:ems="10"
android:hint="Enter the text to be converted"
android:inputType="textPersonName"
android:text="" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="162dp"
android:onClick="convert"
android:layout_marginRight="162dp"
android:layout_marginBottom="329dp"
android:text="Convert" />
</RelativeLayout>
JAVA CODE
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import java.util.Locale;
public class MainActivity extends AppCompatActivity {
TextToSpeech t1;
EditText e1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e1 = findViewById(R.id.editText);
t1 = new TextToSpeech(getApplicationContext(), new
TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status!=TextToSpeech.ERROR){
t1.setLanguage(Locale.UK);
}
}
});
}
public void convert(View view){
String tospeak = e1.getText().toString();
t1.speak(tospeak,TextToSpeech.QUEUE_FLUSH,null);
}
}
OUTPUT
Program-8: Create an activity like a phone dialer with CALL and SAVE buttons. On
pressing the CALL button, it must call the phone number and on pressing the SAVE button it
must save the number to the phone contacts.
XML CODE
<TextView
android:layout_width="298dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="54dp"
android:layout_marginBottom="575dp"
android:text="Call Application"
android:textSize="36dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/phoneNumberEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="176dp"
android:layout_marginBottom="462dp"
android:ems="10"
android:inputType="phone" />
<Button
android:id="@+id/clearBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="52dp"
android:layout_marginBottom="459dp"
android:text="Clear" />
<Button
android:id="@+id/button9"
android:layout_width="76dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="137dp"
android:layout_marginBottom="206dp"
android:onClick="inputNumber"
android:text="8" />
<Button
android:id="@+id/button3"
android:layout_width="76dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="132dp"
android:layout_marginBottom="341dp"
android:onClick="inputNumber"
android:text="2" />
<Button
android:id="@+id/button4"
android:layout_width="76dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="34dp"
android:layout_marginBottom="337dp"
android:onClick="inputNumber"
android:text="3" />
<Button
android:id="@+id/button5"
android:layout_width="76dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="244dp"
android:layout_marginBottom="272dp"
android:onClick="inputNumber"
android:text="4" />
<Button
android:id="@+id/button6"
android:layout_width="76dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="139dp"
android:layout_marginBottom="272dp"
android:onClick="inputNumber"
android:text="5" />
<Button
android:id="@+id/button7"
android:layout_width="76dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="32dp"
android:layout_marginBottom="269dp"
android:onClick="inputNumber"
android:text="6" />
<Button
android:id="@+id/button2"
android:layout_width="76dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="240dp"
android:layout_marginBottom="341dp"
android:onClick="inputNumber"
android:text="1" />
<Button
android:id="@+id/button8"
android:layout_width="76dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="246dp"
android:layout_marginBottom="206dp"
android:onClick="inputNumber"
android:text="7" />
<Button
android:id="@+id/button11"
android:layout_width="76dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="238dp"
android:layout_marginBottom="142dp"
android:onClick="inputNumber"
android:text="#" />
<Button
android:id="@+id/button12"
android:layout_width="76dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="135dp"
android:layout_marginBottom="136dp"
android:onClick="inputNumber"
android:text="0" />
<Button
android:id="@+id/button13"
android:layout_width="76dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="32dp"
android:layout_marginBottom="142dp"
android:onClick="inputNumber"
android:text="*" />
<Button
android:id="@+id/callBtn"
android:layout_width="76dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="188dp"
android:layout_marginBottom="65dp"
android:text="Call" />
<Button
android:id="@+id/saveBtn"
android:layout_width="76dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="74dp"
android:layout_marginBottom="68dp"
android:text="Save" />
<Button
android:id="@+id/button10"
android:layout_width="76dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="32dp"
android:layout_marginBottom="203dp"
android:onClick="inputNumber"
android:text="9" />
</RelativeLayout>
JAVA CODE
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
EditText phoneNumberEditText;
Button clearBtn,callBtn,saveBtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
phoneNumberEditText=findViewById(R.id.phoneNumberEditText);
callBtn=findViewById(R.id.callBtn);
saveBtn=findViewById(R.id.saveBtn);
clearBtn=findViewById(R.id.clearBtn);
clearBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
phoneNumberEditText.setText("");
}
});
callBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String
phoneNumber=phoneNumberEditText.getText().toString();
Intent intent=new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:"+phoneNumber));
startActivity(intent);
}
});
saveBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String
phoneNumber=phoneNumberEditText.getText().toString();
Intent intent=new Intent(Intent.ACTION_INSERT);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
intent.putExtra(ContactsContract.Intents.Insert.PHONE,phoneNumber);
startActivity(intent);
}
});
}
public void inputNumber(View V){
Button btn=(Button)V;
String digit=btn.getText().toString();
String phoneNumber=phoneNumberEditText.getText().toString();
phoneNumberEditText.setText(phoneNumber +digit);
}
}
OUTPUT
Viva Questions
1 What is Android?
2 What Is the Google Android SDK?
3 What is the Android Architecture?
4 Describe the Android Framework.
5 What is the importance of having an emulator within the Android environment?
6 What is the importance of XML-based layouts?
7 What items are important in every Android project?
8 Name the languages supported for Android development
9 What are Intents?
10 Describe Activities.
11 What is ConstraintLayout?
12 What is the AndroidManifest.xml?
13 What are the different versions of Android OS?
14 What is Query Language?
15 What is SQLite?
16 Who was the designer of SQLite?
17 What are the most important features of SQLite?
18 What are the advantages of using SQLite?
19 How would you create a database in SQLite?
20 How would you create a table in SQLite database?
21 How can you delete the existing records from a table in SQLite?
22 Explain the difference between SQL and SQLite.
23 List Out The Standard Sqlite Commands?
24 What is drawable folder in android?
25 How to launch an activity in android?
26 What is .apk extension in Android?
27 Describe Lifecycle of an Activity.
28 What is Toast in Android?