18CSMP68 Jssateb SKN PM
18CSMP68 Jssateb SKN PM
18CSMP68 Jssateb SKN PM
LABORATORY MANUAL
Mobile Application Development 18CSMP68
Veion 1.
Editorial Committee
Dr. Sowmya K.N, Department of ISE
Mrs. Punitha M, Department of ISE
Approved by
H.O.D, Department of ISE
Document Log
ABOUT JSSATEB
JSS Academy of Technical Education (JSSATE) was established in the year 1997 at Bengaluru and is
under the umbrella of JSS Mahavidyapeetha, Mysuru. JSSATE is the result of the vision of our
President, His Holiness Jagadguru Sri Shivarathri Deshikendra Mahaswamiji to proactively participate
in establishing a world class Institution for Technical Education. The Campus is located on a sprawling
21.17 acres land surrounded by lush green plantation on the South-Western edge of Bengaluru City.
The institution is affiliated to Visvesvaraya Technological University (VTU), Belagavi, India
The Student forum SAMYOG is solely for the benefit of the student community established with the
aim of by the students, of the students and from the students. The students actively take part in co-
curricular activities like projects, paper & poster presentations, coding, debugging, etc. In the extra-
curricular events like NSS, sports, college fest, and the preparation of technical magazines &
newsletters. They are also participating in self-initiated outreach activities like YODHA , Book
borrow.com, bookbeka.com, medical camps like blood donation camps, eye testing camps, dental
camps, and Ayurvedic camps, etc. Industry interaction is established through MOUs. A good number
of industrial visits, Invited lecturers, workshops, seminars, and webinars are also organized regularly
in emerging technologies from experts of industries and institutions.
Most of our students are well placed in fortune 500 companies. Our students have recorded very good
performance in competitive examinations such as GATE, GRE, GMAT, TOEFL, CAT, PGCET, etc.
Many of our Alumni joined MS programs in the leading and reputed Universities in the world.
To be among the finest Institutions providing Engineering and Management Education empowered with
To emerge as a centre of academic excellence, by producing competent professionals to meet the global
Prepare the competent professionals to meet the advancements in the industry and academia by imparting
Enrich the technical ability of students to face the world with confidence, commitment and team-work.
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.
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.
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 valid conclusions.
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.
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
engineering practice.
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 sustainable
development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of
the engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader in diverse
teams, and in multidisciplinary settings.
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.
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 member and leader in a team, to
manage projects and in multidisciplinary environments.
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.
Course Details
Course Objectives
Course Outcomes
2. Construct adaptive, responsive user interfaces that work across a wide range of devices.
4. Experiment with various methods in storing, sharing and retrieving data in Android
applications
SYLLABUS
MOBILE APPLICATION DEVELOPMENT
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 purposes 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
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.
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.
Program 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.
Program 4
Develop an application to set an image as wallpaper. On click of a button, the wallpaper image
should start to change randomly every 30 seconds.
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
TextView control.
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.
Program 7
Develop a simple application with one Edit Text 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.
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.
PART B
Program 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.
Program 2
Develop a content provider application with an activity called “Meeting Schedule” which takes
Date, Time and Meeting Agenda as input from the user and store this information into the SQLite
database. Create another application with an activity called “Meeting Info” having DatePicker
control, which on the selection of a date should display the Meeting Agenda information for that
particular date, else it should display a toast message saying “No Meeting on this Date”.
Program 3
Create an application to receive an incoming SMS which is notified to the user. On clicking this
SMS notification, the message content and the number should be displayed on the screen. Use
appropriate emulator control to send the SMS message to your application.
Program 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
“FirstCreate a File”.
Page 9
Dept. of ISE, JSSATE, 2020-21
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
Program 5
Create an application to demonstrate a basic media player that allows the user to Forward,
Backward, Play and Pause an audio. Also, make use of the indicator in the seek bar to move the
audio forward or backward as required.
Program 6
Program 7
Develop an application that makes use of the clipboard framework for copying and pasting of the
text. The activity consists of two EditText controls and two Buttons to trigger the copy and paste
functionality.
Program 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 Principal Amount, 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.
Course Outcomes
After successful completion of the Course, the participants will be able to
C323.2 Construct adaptive, responsive user interfaces that work across a wide
range of devices.
Analyze long running tasks and background work in Android applications.
C323.3
C323.4 Experiment with various methods in storing, sharing and retrieving data
in Android applications
C323.5 Inspect the role of permissions and security for Android applications.
CO-PO Mapping
CO No. PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
C323.1 3 2 2 - 2 1 - - 1 1 - 1
C323.2 3 2 2 - 2 1 - - 1 1 - 1
C323.3 3 2 2 - 2 1 - - 1 1 - 1
C323.4 3 2 2 - 2 1 - 2 1 1 - 1
C323.5 3 2 2 - 2 1 - 2 1 1 - 1
Experiment distribution
For laboratories having only one part: Students are allowed to pick one experiment from
the lot with equal opportunity.
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.
Select Android Q, if not already downloaded press download, After download completes Select
Q and Press Next Button.
While creating a New Project for First Time, make sure Android Studio is connected to internet,
It downloads the required packages from internet.
Go to File New New Project
In Configure your Project Screen, Enter below details and Press Finish Button.
Enter Name of the Application This will be application name this will be visible with Home
Screen Icon.
Package Name Enter package name atleast two identifier (Eg: com.example). Best Practice
is3 or more identifier (Eg: com.example.firstapp).
Basic View:
Right Click on app folder New Folder Assets Folder Press Finish Button
Programs
PART A
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.
Design
TextView
activity_main.xml
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="COMPANY NAME"
android:textSize="16dp"
android:textColor="#000000"
android:id="@+id/lbl_company_name"
android:layout_marginRight="10dp" />
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/email_icon"
android:layout_toRightOf="@id/lbl_company_name"
android:layout_marginLeft="10dp"/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
Dept. of ISE, JSSATE, 2020-21 Page 28
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
android:background="#000000"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name:"
android:textSize="16dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:textColor="#000000"
android:gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Job Title:"
android:textSize="16dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:textColor="#000000"
android:gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Phone Number:"
android:textSize="16dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:textColor="#000000"
android:gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Address:"
android:textSize="16dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:textColor="#000000"
android:gravity="center"
Dept. of ISE, JSSATE, 2020-21 Page 29
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Email, Website, Fax"
android:textSize="16dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:textColor="#000000"
android:gravity="center"
/>
</LinearLayout>
Sample 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.
TextView
EditText
Button
activity_main.xml
<Button
android:id="@+id/btn_clear"
android:layout_width="90dp"
android:layout_height="49dp"
android:layout_marginTop="30dp"
android:text="C"
app:layout_constraintStart_toStartOf="@+id/btn_add"
app:layout_constraintTop_toBottomOf="@+id/btn_add" />
<Button
android:id="@+id/btn_sub"
android:layout_width="90dp"
android:layout_height="0dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="-"
app:layout_constraintStart_toEndOf="@+id/button_three"
app:layout_constraintTop_toBottomOf="@+id/btn_mul" />
<Button
android:id="@+id/btn_add"
android:layout_width="90dp"
android:layout_height="0dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="+"
app:layout_constraintStart_toEndOf="@+id/button_equal"
app:layout_constraintTop_toBottomOf="@+id/btn_sub" />
<Button
android:id="@+id/btn_mul"
android:layout_width="90dp"
Dept. of ISE, JSSATE, 2020-21 Page 34
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
android:layout_height="0dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="*"
app:layout_constraintStart_toEndOf="@+id/button_six"
app:layout_constraintTop_toBottomOf="@+id/btn_div" />
<Button
android:id="@+id/button_equal"
android:layout_width="55dp"
android:layout_height="41dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="="
app:layout_constraintStart_toEndOf="@+id/button_zero"
app:layout_constraintTop_toBottomOf="@+id/button_three" />
<Button
android:id="@+id/button_zero"
android:layout_width="55dp"
android:layout_height="41dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="0"
app:layout_constraintStart_toEndOf="@+id/button_dot"
app:layout_constraintTop_toBottomOf="@+id/btn_two" />
<Button
android:id="@+id/button_dot"
android:layout_width="55dp"
android:layout_height="41dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="."
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_one" />
<Button
android:id="@+id/button_three"
android:layout_width="55dp"
android:layout_height="41dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="3"
Dept. of ISE, JSSATE, 2020-21 Page 35
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
app:layout_constraintStart_toEndOf="@+id/btn_two"
app:layout_constraintTop_toBottomOf="@+id/button_six" />
<Button
android:id="@+id/btn_two"
android:layout_width="55dp"
android:layout_height="41dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="2"
app:layout_constraintStart_toEndOf="@+id/btn_one"
app:layout_constraintTop_toBottomOf="@+id/button_five" />
<Button
android:id="@+id/btn_one"
android:layout_width="55dp"
android:layout_height="41dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button_four" />
<Button
android:id="@+id/button_six"
android:layout_width="55dp"
android:layout_height="41dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="6"
app:layout_constraintStart_toEndOf="@+id/button_five"
app:layout_constraintTop_toBottomOf="@+id/button_nine" />
<Button
android:id="@+id/btn_seven"
android:layout_width="62dp"
android:layout_height="53dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="7"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_result" />
<Button
Dept. of ISE, JSSATE, 2020-21 Page 36
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
android:id="@+id/btn_eight"
android:layout_width="56dp"
android:layout_height="51dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="8"
app:layout_constraintStart_toEndOf="@+id/btn_seven"
app:layout_constraintTop_toBottomOf="@+id/txt_result" />
<Button
android:id="@+id/button_nine"
android:layout_width="64dp"
android:layout_height="53dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="8"
app:layout_constraintStart_toEndOf="@+id/btn_eight"
app:layout_constraintTop_toBottomOf="@+id/txt_result" />
<Button
android:id="@+id/button_four"
android:layout_width="57dp"
android:layout_height="41dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_seven" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="Calculator"
android:textSize="26dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Dept. of ISE, JSSATE, 2020-21 Page 37
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="Result"
android:textSize="18dp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@+id/textView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<EditText
android:id="@+id/txt_result"
android:layout_width="310dp"
android:layout_height="46dp"
android:layout_marginTop="20dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintStart_toStartOf="@+id/textView2"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
<Button
android:id="@+id/btn_div"
android:layout_width="87dp"
android:layout_height="49dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="/"
app:layout_constraintStart_toEndOf="@+id/button_nine"
app:layout_constraintTop_toBottomOf="@+id/txt_result" />
<Button
android:id="@+id/button_five"
android:layout_width="55dp"
android:layout_height="41dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="5"
app:layout_constraintStart_toEndOf="@+id/button_four"
app:layout_constraintTop_toBottomOf="@+id/btn_eight" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.partaprogram2;
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;
Button add,sub,mul,div;
Button btnClear,btnEqual,btnDot;
EditText txtResult;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnOne=(Button)findViewById(R.id.btn_one);
btnOne.setOnClickListener(this);
btnTwo=(Button)findViewById(R.id.btn_two);
btnTwo.setOnClickListener(this);
btnThree=(Button)findViewById(R.id.button_nine);
btnThree.setOnClickListener(this);
btnFour=(Button)findViewById(R.id.button_four);
btnFour.setOnClickListener(this);
btnFive=(Button)findViewById(R.id.button_five);
btnFive.setOnClickListener(this);
btnSix=(Button)findViewById(R.id.button_six);
btnSix.setOnClickListener(this);
Dept. of ISE, JSSATE, 2020-21 Page 39
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
btnSeven=(Button)findViewById(R.id.btn_seven);
btnSeven.setOnClickListener(this);
btnEight=(Button)findViewById(R.id.btn_eight);
btnEight.setOnClickListener(this);
btnNine=(Button)findViewById(R.id.button_nine);
btnNine.setOnClickListener(this);
add=(Button)findViewById(R.id.btn_add);
add.setOnClickListener(this);
sub=(Button)findViewById(R.id.btn_sub);
sub.setOnClickListener(this);
mul=(Button)findViewById(R.id.btn_mul);
mul.setOnClickListener(this);
div=(Button)findViewById(R.id.btn_div);
div.setOnClickListener(this);
btnClear=(Button)findViewById(R.id.btn_clear);
btnClear.setOnClickListener(this);
btnEqual=(Button)findViewById(R.id.button_equal);
btnEqual.setOnClickListener(this);
btnDot=(Button)findViewById(R.id.button_dot);
btnDot.setOnClickListener(this);
txtResult=(EditText)findViewById(R.id.txt_result);
txtResult.setText("");
} else if (data.contains("*")) {
String[] operands = data.split(Pattern.quote("*"));
if(operands.length==2) {
double operand1 = Double.parseDouble(operands[0]);
double operand2 = Double.parseDouble(operands[1]);
double result = operand1 * operand2;
txtResult.setText(String.valueOf(result));
}
else
{
Toast.makeText(getBaseContext(),
"Invalid Input",
Toast.LENGTH_LONG).show();
}
} else if (data.contains("+")) {
String[] operands = data.split(Pattern.quote("+"));
if(operands.length==2) {
double operand1 = Double.parseDouble(operands[0]);
double operand2 = Double.parseDouble(operands[1]);
double result = operand1 + operand2;
txtResult.setText(String.valueOf(result));
}
else
{
Toast.makeText(getBaseContext(),
"Invalid Input",
Toast.LENGTH_LONG).show();
Dept. of ISE, JSSATE, 2020-21 Page 42
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
}
} else if (data.contains("-")) {
String[] operands = data.split("-");
if(operands.length==2) {
double operand1 = Double.parseDouble(operands[0]);
double operand2 = Double.parseDouble(operands[1]);
double result = operand1 - operand2;
txtResult.setText(String.valueOf(result));
}
else
{
Toast.makeText(getBaseContext(),
"Invalid Input",
Toast.LENGTH_LONG).show();
}
}
}
catch(Exception e)
{
Toast.makeText(getBaseContext(),
"Invalid Input",
Toast.LENGTH_LONG).show();
}
}
if(v.equals(add))
{
txtResult.append("+");
}
if(v.equals(sub))
{
txtResult.append("-");
}
if(v.equals(mul))
{
txtResult.append("*");
}
if(v.equals(div))
{
txtResult.append("/");
}
Dept. of ISE, JSSATE, 2020-21 Page 43
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
}
}
Type id value
here i.e.,btn_One
Implements
View.OnClickList
ener
Button
btnOne;
btnOne=(Button)findView
ById(R.id.btn_one);
btnOne.setOnClickListene
r(this);
Sample Output
Program 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.
Design
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">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:text="SIGN UP"
android:textColor="@android:color/background_dark"
android:textSize="22dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView3"
Dept. of ISE, JSSATE, 2020-21 Page 47
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="50dp"
android:text="USERNAME"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
<TextView
android:id="@+id/textView4"
android:layout_width="68dp"
android:layout_height="0dp"
android:layout_marginTop="50dp"
android:text="Password"
app:layout_constraintStart_toStartOf="@+id/textView3"
app:layout_constraintTop_toBottomOf="@+id/textView3" />
<EditText
android:id="@+id/txt_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginEnd="10dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintBottom_toBottomOf="@+id/textView3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView3"
app:layout_constraintTop_toTopOf="@+id/textView3" />
<EditText
android:id="@+id/txt_password"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginTop="26dp"
android:ems="10"
android:inputType="textPassword"
app:layout_constraintEnd_toEndOf="@+id/txt_username"
app:layout_constraintStart_toStartOf="@+id/txt_username"
app:layout_constraintTop_toBottomOf="@+id/txt_username" />
<Button
android:id="@+id/btn_signup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Dept. of ISE, JSSATE, 2020-21 Page 48
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
android:layout_marginTop="30dp"
android:text="Sign Up"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_password" />
</androidx.constraintlayout.widget.ConstraintLayout>
Activity_login.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=".LoginActivity">
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Login"
android:textSize="22dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="50dp"
android:text="Username"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView7" />
<EditText
android:id="@+id/txt_login_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:ems="10"
android:inputType="textPersonName"
Dept. of ISE, JSSATE, 2020-21 Page 49
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
android:text="Name"
app:layout_constraintBottom_toBottomOf="@+id/textView9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView9"
app:layout_constraintTop_toTopOf="@+id/textView9" />
<TextView
android:id="@+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="50dp"
android:text="Password"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView9" />
<EditText
android:id="@+id/txt_login_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword"
app:layout_constraintEnd_toEndOf="@+id/txt_login_username"
app:layout_constraintStart_toStartOf="@+id/txt_login_username"
app:layout_constraintTop_toTopOf="@+id/textView10" />
<Button
android:id="@+id/btn_login_signin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Login"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_login_password" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.parta.program3;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.PatternMatcher;
Dept. of ISE, JSSATE, 2020-21 Page 50
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
EditText txtUsername;
EditText txtPassword;
Button btnSignup;
String regularExpression
="^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d)(?=.*[@$!])[A-Za-z\\d@$!]{8,}$";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtUsername=(EditText)findViewById(R.id.txt_username);
txtPassword=(EditText)findViewById(R.id.txt_password);
btnSignup=(Button)findViewById(R.id.btn_signup);
btnSignup.setOnClickListener(this);
if(validatePassword(password)) {
Bundle bundle = new Bundle();
bundle.putString("user", username);
bundle.putString("pass", password);
}
}
LoginActivity.java
package com.example.parta.program3;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
EditText txtLoginUsername;
EditText txtLoginPassword;
Button btnLogin;
String user,pass;
int count=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Dept. of ISE, JSSATE, 2020-21 Page 52
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
setContentView(R.layout.activity_login);
txtLoginUsername=(EditText)
findViewById(R.id.txt_login_username);
txtLoginPassword=(EditText)
findViewById(R.id.txt_login_password);
btnLogin=(Button)findViewById(R.id.btn_login_signin);
btnLogin.setOnClickListener(this);
Bundle bundle=getIntent().getBundleExtra("data");
user=bundle.getString("user");
pass=bundle.getString("pass");
if(user.equals(user1)&&pass.equals(pass1))
{
Toast.makeText(this,"Login Successful"
,Toast.LENGTH_LONG).show();
}
else
{
count++;
if(count==2)
{
btnLogin.setEnabled(false);
Toast.makeText(this,
"Failed Login Attempts "+count
,Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(this,"Login Failed "+count
,Toast.LENGTH_LONG).show();
}
}
}
Program 4
Develop an application to set an image as wallpaper. On click of a button, the wallpaper image
should start to change randomly every 30 seconds.
Text View
Button
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Click here to Change Wallpaper"
android:id="@+id/btn_start_change_wallpaper"/>
</LinearLayout>
MainActivity.java
package com.example.program4;
import androidx.appcompat.app.AppCompatActivity;
import android.app.WallpaperManager;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import java.util.Timer;
import java.util.TimerTask;
Button btnChangeWallpaper;
boolean running;
int i=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnChangeWallpaper=(Button)
findViewById(R.id.btn_start_change_wallpaper);
btnChangeWallpaper.setOnClickListener(this);
try {
WallpaperManager wallpaperManager =
WallpaperManager.getInstance(getBaseContext());
if(i==4)
{
i=1;
}
if(i==2)
{
i=3;
}
if(i==3)
{
i=2;
}
if(i==1)
{
i=3;
}
wallpaperManager.setBitmap
(BitmapFactory.decodeResource(getResources()
,imagesArray[i]));
i++;
}
catch(Exception e)
{
}
}
}
AndriodManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.program4">
<uses-permission android:name="android.permission.SET_WALLPAPER"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
Dept. of ISE, JSSATE, 2020-21 Page 58
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
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.
Design:
Text View
Plain Text
Button
activity_main.xml
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:text="Counter Application"
android:textSize="18dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Dept. of ISE, JSSATE, 2020-21 Page 66
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/lbl_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="0"
android:textColor="@color/colorAccent"
android:textSize="50dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<Button
android:id="@+id/btn_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Start"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/lbl_text" />
<Button
android:id="@+id/btn_stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="Stop"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_start" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.program5;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
Dept. of ISE, JSSATE, 2020-21 Page 67
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
import android.widget.TextView;
import org.w3c.dom.Text;
TextView lblCounter;
Button btnStart,btnStop;
int counter=0;
boolean running=false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lblCounter=(TextView)findViewById(R.id.lbl_text);
btnStart=(Button)findViewById(R.id.btn_start);
btnStop=(Button)findViewById(R.id.btn_stop);
btnStop.setOnClickListener(this);
btnStart.setOnClickListener(this);
}
};
}
}
}
}
}
Sample 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.
Design
activity_main.xml
<Button
android:id="@+id/btn_parsexml"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="150dp"
android:text="Parse XML"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Dept. of ISE, JSSATE, 2020-21 Page 74
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btn_parsejson"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:text="Parse Json"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_parsexml" />
</androidx.constraintlayout.widget.ConstraintLayout>
activity_view.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=".ViewActivity2">
<TextView android:id="@+id/lbl_xml_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="Xml Data"
app:layout_constraintStart_toStartOf="@+id/textView2"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:text="PARSING XML AND JSON DATA"
android:textColor="@color/black"
android:textSize="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
Dept. of ISE, JSSATE, 2020-21 Page 75
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="40dp"
android:text="XML DATA"
android:textColor="@color/black"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_marginEnd="40dp"
android:text="JSON DATA"
android:textColor="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<TextView android:id="@+id/lbl_json_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="Json Data"
app:layout_constraintEnd_toEndOf="@+id/textView3"
app:layout_constraintTop_toBottomOf="@+id/textView3" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.parsingxmltojsondata;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
Button btnParseXml,btnParseJson;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnParseXml=(Button)findViewById(R.id.btn_parsexml);
btnParseJson=(Button)findViewById(R.id.btn_parsejson);
btnParseJson.setOnClickListener(this);
btnParseXml.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if(v.equals(btnParseJson))
{
Intent it=new Intent(this,ViewActivity2.class);
it.putExtra("mode",1);
startActivity(it);
}
else if(v.equals(btnParseXml))
{
Intent it=new Intent(this,ViewActivity2.class);
it.putExtra("mode",2);
startActivity(it);
}
}
}
ViewActivity.java
package com.example.parsingxmltojsondata;
import androidx.appcompat.app.AppCompatActivity;
Dept. of ISE, JSSATE, 2020-21 Page 77
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
import android.os.Bundle;
import android.widget.TextView;
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 javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
int mode=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view2);
lblXmlData=(TextView)findViewById(R.id.lbl_xml_data);
lblJsonData=(TextView)findViewById(R.id.lbl_json_data);
mode=getIntent().getIntExtra("mode",0);
if(mode==1)
{
parseJson();
}
else
{
parseXmlDocument();
}
}
public String parseXmlDocument()
{
try {
InputStream is = getAssets().open("input.xml");
DocumentBuilderFactory dbFactory =
DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(is);
Dept. of ISE, JSSATE, 2020-21 Page 78
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
Element element=doc.getDocumentElement();
element.normalize();
NodeList nList = doc.getElementsByTagName("employee");
for (int i=0; i<nList.getLength(); i++) {
Node node = nList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element2 = (Element) node;
lblXmlData.setText("City Name : " + getValue("city_name",
element2)+"\n");
lblXmlData.append("Latitude : " + getValue("Latitude",
element2)+"\n");
lblXmlData.append("Longitude : " + getValue("Longitude",
element2)+"\n");
lblXmlData.append("Temperature : " + getValue("Temperature",
element2)+"\n");
lblXmlData.append("Humidity : " + getValue("Humidity",
element2)+"\n");
}
}
} catch (Exception e) {e.printStackTrace();}
return null;
}
lblJsonData.append("Latitude:"+jsonObject1.getString("Latitude")+"\n");
Dept. of ISE, JSSATE, 2020-21 Page 79
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
lblJsonData.append("Longitude"+jsonObject1.getString("Longitude")+"\n");
lblJsonData.append("Temperature:"+jsonObject1.getInt("Temperature")+"\
n");
lblJsonData.append("Humidity"+jsonObject1.getString("Humidity")+"\n");
} catch (Exception e) {
e.printStackTrace();
}
}
}
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.
Design
Plain Text
Edit Text
Button
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">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="200dp"
android:text="TEXT TO SPEECH APPLICATION"
android:textColor="@color/purple_700"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btn_speak"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:text="CONVERT TEXT TO SPEECH"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText" />
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="@+id/textView"
app:layout_constraintStart_toStartOf="@+id/textView"
Dept. of ISE, JSSATE, 2020-21 Page 88
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
app:layout_constraintTop_toBottomOf="@+id/textView" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.texttospeech;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
EditText txtSpeak;
Button btnSpeak;
TextToSpeech textToSpeech;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtSpeak=(EditText)findViewById(R.id.editText);
btnSpeak=(Button)findViewById(R.id.btn_speak);
btnSpeak.setOnClickListener(this);
textToSpeech=new TextToSpeech(getBaseContext(),
new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if(status!=TextToSpeech.ERROR)
{
Toast.makeText(getBaseContext(),
"Success",
Toast.LENGTH_LONG).show();
}
}
});
}
TextToSpeech.QUEUE_FLUSH,null);
Dept. of ISE, JSSATE, 2020-21 Page 90
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
}
}
Sample 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.
Design
Text View
Edit Text
Button
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">
<TextView
android:id="@+id/textView2"
android:layout_width="309dp"
android:layout_height="33dp"
android:layout_marginTop="50dp"
android:text="CALL AND SAVE APPLICATION"
android:textColor="@color/black"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/txt_phonenumber"
android:layout_width="137dp"
android:layout_height="58dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="30dp"
android:ems="10"
android:inputType="textPersonName"
android:text="0123456789"
android:textSize="24sp"
app:layout_constraintEnd_toStartOf="@+id/btn_delete"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
<Button
android:id="@+id/btn_delete"
android:layout_width="105dp"
android:layout_height="69dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="60dp"
Dept. of ISE, JSSATE, 2020-21 Page 95
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
android:text="DEL"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
<Button
android:id="@+id/btn_four"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="40dp"
android:text="4"
android:textSize="24sp"
app:layout_constraintEnd_toStartOf="@+id/btn_five"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_one" />
<Button
android:id="@+id/btn_five"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="40dp"
android:text="5"
android:textSize="24sp"
app:layout_constraintEnd_toStartOf="@+id/btn_six"
app:layout_constraintStart_toEndOf="@+id/btn_four"
app:layout_constraintTop_toBottomOf="@+id/btn_two" />
<Button
android:id="@+id/btn_six"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="50dp"
android:text="6"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/btn_five"
app:layout_constraintTop_toBottomOf="@+id/btn_three" />
<Button
android:id="@+id/btn_eight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="40dp"
android:text="8"
android:textSize="24sp"
app:layout_constraintEnd_toStartOf="@+id/btn_nine"
app:layout_constraintStart_toEndOf="@+id/btn_seven"
app:layout_constraintTop_toBottomOf="@+id/btn_five" />
<Button
android:id="@+id/btn_nine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="50dp"
android:text="9"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/btn_eight"
app:layout_constraintTop_toBottomOf="@+id/btn_six" />
<Button
android:id="@+id/btn_star"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
Dept. of ISE, JSSATE, 2020-21 Page 97
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
android:layout_marginTop="40dp"
android:layout_marginEnd="40dp"
android:text="*"
android:textSize="24sp"
app:layout_constraintEnd_toStartOf="@+id/btn_zero"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_seven" />
<Button
android:id="@+id/btn_zero"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="40dp"
android:text="0"
android:textSize="24sp"
app:layout_constraintEnd_toStartOf="@+id/btn_hash"
app:layout_constraintStart_toEndOf="@+id/btn_star"
app:layout_constraintTop_toBottomOf="@+id/btn_eight" />
<Button
android:id="@+id/btn_hash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="50dp"
android:text="#"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/btn_zero"
app:layout_constraintTop_toBottomOf="@+id/btn_nine" />
<Button
android:id="@+id/btn_call"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="100dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="40dp"
android:text="CALL"
android:textSize="24sp"
app:layout_constraintEnd_toStartOf="@+id/btn_save"
Dept. of ISE, JSSATE, 2020-21 Page 98
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_star" />
<Button
android:id="@+id/btn_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="100dp"
android:text="SAVE"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/btn_call"
app:layout_constraintTop_toBottomOf="@+id/btn_hash" />
<Button
android:id="@+id/btn_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="40dp"
android:text="1"
android:textSize="24sp"
app:layout_constraintEnd_toStartOf="@+id/btn_two"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_phonenumber" />
<Button
android:id="@+id/btn_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="40dp"
android:text="2"
android:textSize="24sp"
app:layout_constraintEnd_toStartOf="@+id/btn_three"
app:layout_constraintStart_toEndOf="@+id/btn_one"
app:layout_constraintTop_toBottomOf="@+id/txt_phonenumber" />
<Button
android:id="@+id/btn_three"
Dept. of ISE, JSSATE, 2020-21 Page 99
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="50dp"
android:text="3"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/btn_two"
app:layout_constraintTop_toBottomOf="@+id/txt_phonenumber" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.callapp;
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;
Button btnOne,btnTwo,btnThree,btnFour,btnFive;
Button btnSix,btnSeven,btnEight,btnNine,btnZero;
Button btnDel,btnStar,btnHash,btnCall,btnSave;
EditText txtPhonenumber;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnOne=(Button)findViewById(R.id.btn_one);
btnOne.setOnClickListener(this);
btnTwo=(Button)findViewById(R.id.btn_two);
btnTwo.setOnClickListener(this);
btnThree=(Button)findViewById(R.id.btn_three);
Dept. of ISE, JSSATE, 2020-21 Page 100
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
btnThree.setOnClickListener(this);
btnFour=(Button)findViewById(R.id.btn_four);
btnFour.setOnClickListener(this);
btnFive=(Button)findViewById(R.id.btn_five);
btnFive.setOnClickListener(this);
btnSix=(Button)findViewById(R.id.btn_six);
btnSix.setOnClickListener(this);
btnSeven=(Button)findViewById(R.id.btn_seven);
btnSeven.setOnClickListener(this);
btnEight=(Button)findViewById(R.id.btn_eight);
btnEight.setOnClickListener(this);
btnNine=(Button)findViewById(R.id.btn_nine);
btnNine.setOnClickListener(this);
btnZero=(Button)findViewById(R.id.btn_zero);
btnZero.setOnClickListener(this);
btnStar=(Button)findViewById(R.id.btn_star);
btnStar.setOnClickListener(this);
btnHash=(Button)findViewById(R.id.btn_hash);
btnHash.setOnClickListener(this);
btnCall=(Button)findViewById(R.id.btn_call);
btnCall.setOnClickListener(this);
btnSave=(Button)findViewById(R.id.btn_save);
btnSave.setOnClickListener(this);
btnDel=(Button)findViewById(R.id.btn_delete);
btnDel.setOnClickListener(this);
txtPhonenumber=(EditText)findViewById(R.id.txt_phonenumber);
txtPhonenumber.setText("");
}
if(v.equals(btnOne))
{
txtPhonenumber.append("1");
}
else if(v.equals(btnTwo))
{
txtPhonenumber.append("2");
}
else if(v.equals(btnThree))
{
txtPhonenumber.append("3");
}
else if(v.equals(btnFour))
{
txtPhonenumber.append("4");
}
else if(v.equals(btnFive))
{
txtPhonenumber.append("5");
}
else if(v.equals(btnSix))
{
txtPhonenumber.append("6");
}
else if(v.equals(btnSeven))
{
txtPhonenumber.append("7");
}
else if(v.equals(btnEight))
{
txtPhonenumber.append("8");
}
else if(v.equals(btnNine))
{
txtPhonenumber.append("9");
}
else if(v.equals(btnZero))
{
txtPhonenumber.append("0");
}
else if(v.equals(btnStar))
Dept. of ISE, JSSATE, 2020-21 Page 102
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
{
txtPhonenumber.append("*");
}
else if(v.equals(btnHash))
{
txtPhonenumber.append("#");
}
else if(v.equals(btnSave))
{
contactIntent
.putExtra(ContactsContract.Intents.Insert.NAME,
"Unknown");
contactIntent.putExtra(ContactsContract.Intents.Insert.PHONE,
txtPhonenumber.getText().toString());
startActivity(contactIntent);
}
else if(v.equals(btnCall))
{
String data=txtPhonenumber.getText().toString();
Intent it=new Intent(Intent.ACTION_CALL);
it.setData(Uri.parse("tel:"+data));
startActivity(it);
}
else if(v.equals(btnDel))
{
String data=txtPhonenumber.getText().toString();
if(data.length()>0)
{
txtPhonenumber.setText
(data.substring(0,data.length()-1));
}
else
{
txtPhonenumber.setText("");
Dept. of ISE, JSSATE, 2020-21 Page 103
JSS Academy of Technical Education, Bengaluru Mobile Application Development (18CSMP68)
}
}
}
}
AndriodManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.callapp">
<uses-permission
android:name="android.permission.CALL_PHONE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.CallApp">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
Sample Output
Reference Books