100% found this document useful (1 vote)
209 views68 pages

Mad Lab Manual

The document describes how to install Android Studio on Windows, Mac and Linux systems. It provides steps to download and launch the Android Studio installer, accept licenses, and install required SDK components. The document also lists some key libraries needed for 64-bit Linux systems.

Uploaded by

Honnamma sp4257
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
209 views68 pages

Mad Lab Manual

The document describes how to install Android Studio on Windows, Mac and Linux systems. It provides steps to download and launch the Android Studio installer, accept licenses, and install required SDK components. The document also lists some key libraries needed for 64-bit Linux systems.

Uploaded by

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

GOVERNMENT ENGINEERING COLLEGE,

DEVAGIRI, HAVERI-581110

Department of Computer Science


and Engineering

LAB MANUAL
MOBILE APLICATION
DEVELOPMENT
(18CSMP68)
6th Semester CBCS 2018 Scheme

Prepared by
Ms. Chaitra N.Barki
‘Instructions to the Candidates’

1. Students should come with thorough preparation for the


experiment to be conducted.

2. Students will not be permitted to attend the laboratory unless they


bring the practical record fully completed in all respects pertaining
to the experiment conducted in the previous class.

3. Practical record should be neatly maintained.

4. They should obtain the signature of the staff-in-charge in the


observation book after completing each experiment.

5. Theory regarding each experiment should be written in the


practical record before procedure in your own words.

6. Ask lab technician for assistance if you have any problem.

7. Save your class work, assignments in system.

8. Do not download or install software without the assistance of the


laboratory technician.

9. Do not alter the configuration of the system.

10. Turnoff the systems after use.


TABLE OF CONTENTS

1. Introduction
2. Android Studio Installation
Part-A
1. Create an application to design a Visiting Card.
2. Develop an Android application for designing a calculator.
3. Create a SIGN UP activity with Username and password.
4. Develop an application to set an image as wallpaper.
5. Create an activity with two buttons START and STOP (Displaying the
number from one).
6. Develop an application to create an activity with two buttons to
parse the XML and JSON files.
7. Create a button called “Convert Text to Speech” that converts the
user input text into voice.
8. Create an activity like a phone dialer with CALL and SAVE button.
Part-B(Mini Project)
9. 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.
10. Develop a content provider application with an activity called “Meeting
Schedule”
11. Create an application to receive an incoming SMS which is notified to the
user.
12. Write a program to create an activity having a Text box, and also Save,
Open and Create buttons.
13. Create an application to demonstrate a basic media playerthat allows the
user to Forward, Backward, Play and Pause an audio.
14. Develop an application to demonstrate the use of Asynchronous tasks in
android.
15. Develop an application that makes use of the clipboard framework for
copying and pasting of the text.
16. Create an AIDL service that calculates Car Loan EMI
Mobile Application Development (18CSMP68) 2020-21

INTRODUCTION

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 fast and feature-rich emulator

 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

 Extensive testing tools and frameworks

 Lint tools to catch performance, usability, version compatibility, and other problems

 C++ and NDK support

 Built-in support for Google Cloud Platform, making it easy to integrate Google Cloud
Messaging and App Engine

Project structure

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

 Google App Engine modules

Department of CSE, GEC Haveri Page 1


Mobile Application Development (18CSMP68) 2020-21

By default, Android Studio displays your project files in the Android project view, as shown
in figure 1.

Figure 1. The project files in Android view.

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:

 manifests: Contains the AndroidManifest.xml file.

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

Department of CSE, GEC Haveri Page 2


Mobile Application Development (18CSMP68) 2020-21

The user interface

The Android Studio main window is made up of several logical areas identified in figure 2.

Figure 3. The Android Studio main window.

1. The toolbar lets you carry out a wide range of actions, including running your app and
launching Android tools.

2. The navigation bar helps you navigate through your project and open files for editing. It
provides a more compact view of the structure visible in the Project window.

3. The editor window is where you create and modify code. Depending on the current file
type, the editor can change. For example, when viewing a layout file, the editor displays
the Layout Editor.

4. The tool window bar runs around the outside of the IDE window and contains the
buttons that allow you to expand or collapse individual tool windows.

5. The tool windows give you access to specific tasks like project management, search,
version control, and more. You can expand them and collapse them.

6. The status bar displays the status of your project and the IDE itself, as well as any
warnings or messages.

Department of CSE, GEC Haveri Page 3


Mobile Application Development (18CSMP68) 2020-21

Android Studio Installation

Setting up Android Studio takes just a few clicks.

First, be sure you download the latest version of Android Studio.

Windows

To install Android Studio on Windows, proceed as follows:

1. If you downloaded an .exe file (recommended), double-click to launch it.

If you downloaded a .zip file, unpack the ZIP, copy the android-studio folder into
your Program Files folder, and then open the android-studio > bin folder and
launch studio64.exe (for 64-bit machines) or studio.exe (for 32-bit machines).

2. Follow the setup wizard in Android Studio and install any SDK packages that it recommends.

Mac

To install Android Studio on your Mac, proceed as follows:

1. Launch the Android Studio DMG file.

2. Drag and drop Android Studio into the Applications folder, then launch Android Studio.

3. Select whether you want to import previous Android Studio settings, then click OK.

4. The Android Studio Setup Wizard guides you through the rest of the setup, which includes
downloading Android SDK components that are required for development.

Linux

To install Android Studio on Linux, proceed as follows:

1. Unpack the .zip file you downloaded to an appropriate location for your applications, such as
within /usr/local/ for your user profile, or /opt/ for shared users.

If you're using a 64-bit version of Linux, make sure you first install the required libraries for
64-bit machines.

Department of CSE, GEC Haveri Page 4


Mobile Application Development (18CSMP68) 2020-21

2. To launch Android Studio, open a terminal, navigate to the android-studio/bin/ directory, and
execute studio.sh.

3. Select whether you want to import previous Android Studio settings or not, then click OK.

4. The Android Studio Setup Wizard guides you through the rest of the setup, which includes
downloading Android SDK components that are required for development.

Required libraries for 64-bit machines

If you are running a 64-bit version of Ubuntu, you need to install some 32-bit libraries with
the following command:

sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386

If you are running 64-bit Fedora, the command is:

sudo yum install zlib.i686 ncurses-libs.i686 bzip2-libs.i686

Department of CSE, GEC Haveri Page 5


Mobile Application Development(18CSMP68) 2020-21

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.

XML-CODE

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


<RelativeLayoutxmlns: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"
Department of CSE, GEC Haveri Page 6
Mobile Application Development(18CSMP68) 2020-21

android:layout_marginLeft="17dp"
android:layout_marginTop="17dp"
android:layout_marginEnd="244dp"
android:layout_marginRight="244dp"
android:layout_marginBottom="486dp"
android:text="VVCE"
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"
Department of CSE, GEC Haveri Page 7
Mobile Application Development(18CSMP68) 2020-21

android:layout_marginEnd="117dp"
android:layout_marginRight="117dp"
android:layout_marginBottom="394dp"
android:text="Nithin Kumar"
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: 8050462225"
android:textSize="20dp" />

<TextView
android:id="@+id/textView5"

Department of CSE, GEC Haveri Page 8


Mobile Application Development(18CSMP68) 2020-21

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="Kannada Sahitya Parishath Road Gokulam 3rd Stage Mysuru-02"
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(No Change Required)

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

Department of CSE, GEC Haveri Page 9


Mobile Application Development(18CSMP68) 2020-21

OUTPUT:

Department of CSE, GEC Haveri Page 10


Mobile Application Development(18CSMP68) 2020-21

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.

XML-CODE:

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


<RelativeLayoutxmlns: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 CALCI"
android:textSize="38dp"
app:layout_constraintBottom_toBottomOf="parent"
Department of CSE, GEC Haveri Page 11
Mobile Application Development(18CSMP68) 2020-21

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"
Department of CSE, GEC Haveri Page 12
Mobile Application Development(18CSMP68) 2020-21

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"
Department of CSE, GEC Haveri Page 13
Mobile Application Development(18CSMP68) 2020-21

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;
public class MainActivity extends AppCompatActivity {
EditText e1,e2;
TextView tv1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e1 = (EditText)findViewById(R.id.editText1);
e2 = (EditText)findViewById(R.id.editText2);
tv1 = (TextView)findViewById(R.id.textView1);

Department of CSE, GEC Haveri Page 14


Mobile Application Development(18CSMP68) 2020-21

}
public void doAdd(View V){
int a1 = Integer.parseInt(e1.getText().toString());
int a2 = Integer.parseInt(e2.getText().toString());
int result= a1+a2;
tv1.setText(""+result);
}
public void doSub(View V){
int a1 = Integer.parseInt(e1.getText().toString());
int a2 = Integer.parseInt(e2.getText().toString());
int result= a1-a2;
tv1.setText(""+result);
}
public void doMul(View V){
int a1 = Integer.parseInt(e1.getText().toString());
int a2 = Integer.parseInt(e2.getText().toString());
int result= a1*a2;
tv1.setText(""+result);
}
public void doDiv(View V){
int a1 = Integer.parseInt(e1.getText().toString());
int a2 = Integer.parseInt(e2.getText().toString());
float result= a1/a2;
tv1.setText(""+result);
}
}

Department of CSE, GEC Haveri Page 15


Mobile Application Development(18CSMP68) 2020-21

OUTPUT:

Department of CSE, GEC Haveri Page 16


Mobile Application Development(18CSMP68) 2020-21

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.

I. SignUp Activity

activity_signup.xml

<?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"
Department of CSE, GEC Haveri Page 17
Mobile Application Development(18CSMP68) 2020-21

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<TextView

android:layout_width="299dp"

android:layout_height="69dp"

android:layout_alignParentEnd="true"

android:layout_alignParentBottom="true"

android:layout_marginEnd="73dp"

android:layout_marginBottom="606dp"

android:text="SIGNUP PAGE"

android:textAlignment="center"

android:textColor="#120707"

android:textSize="36sp"

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="308dp"

Department of CSE, GEC Haveri Page 18


Mobile Application Development(18CSMP68) 2020-21

android:layout_height="wrap_content"

android:layout_alignParentEnd="true"

android:layout_alignParentBottom="true"

android:layout_marginEnd="42dp"

android:layout_marginBottom="475dp"

android:ems="10"

android:hint="Enetr Email Id"

android:inputType="textPersonName"

android:text=""

android:textSize="30sp" />

<EditText

android:id="@+id/passwordEditText"

android:layout_width="306dp"

android:layout_height="wrap_content"

android:layout_alignParentEnd="true"

android:layout_alignParentBottom="true"

android:layout_marginEnd="41dp"

android:layout_marginBottom="374dp"

android:ems="10"

android:hint="Enter Password"

android:inputType="textPassword"

android:textSize="30sp" />
Department of CSE, GEC Haveri Page 19
Mobile Application Development(18CSMP68) 2020-21

<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="125dp"

android:layout_marginBottom="231dp"

android:text="SIGN UP"

android:textSize="30sp" />

</RelativeLayout>

SignUpActivity.java

import .AppCompatActivity;

import .Intent;

import .Bundle;

import .View;

import .Button;

import .EditText;

import .Toast;

import .Pattern;

public class SignUpActivity extends AppCompatActivity {

EditTextemailEditText, passwordEditText;

Department of CSE, GEC Haveri Page 20


Mobile Application Development(18CSMP68) 2020-21

Button signUpBtn;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_signup);

emailEditText = findViewById(R.id.emailEditText);

passwordEditText = findViewById(R.id.passwordEditText);

signUpBtn = findViewById(R.id.signUpBtn);

signUpBtn.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

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

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

if (!isValidPassword(password)) {

Toast.makeText(SignUpActivity.this, "Password doesn't match


rules",Toast.LENGTH_SHORT).show();

return;

Intent intent = new Intent(SignUpActivity.this, LoginActivity.class);

intent.putExtra("email", email);

intent.putExtra("password", password);

startActivity(intent);

Department of CSE, GEC Haveri Page 21


Mobile Application Development(18CSMP68) 2020-21

});

Pattern lowerCase = Pattern.compile("^.*[a-z].*$");

Pattern upperCase = Pattern.compile("^.*[A-Z].*$");

Pattern number = Pattern.compile("^.*[0-9].*$");

Pattern specialCharacter = Pattern.compile("^.*[^a-zA-Z0-9].*$");

private Boolean isValidPassword(String password) {

// Checks if password length is less than 8

if (password.length() < 8) {

return false;

// Returns false if password doesn't contain a lower case character

if (!lowerCase.matcher(password).matches()) {

return false;

// Returns false if password doesn't contain an upper case character

if (!upperCase.matcher(password).matches()) {

return false;

// Returns false if password doesn't contain a number

if (!number.matcher(password).matches()) {

return false;

}
Department of CSE, GEC Haveri Page 22
Mobile Application Development(18CSMP68) 2020-21

// Returns false if password doesn't contain a special character

if (!specialCharacter.matcher(password).matches()) {

return false;

return true;

II. Login Activity


activity_login.xml

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

<TextView

android:id="@+id/textView"

android:layout_width="217dp"

android:layout_height="80dp"

android:layout_alignParentEnd="true"

android:layout_alignParentBottom="true"
Department of CSE, GEC Haveri Page 23
Mobile Application Development(18CSMP68) 2020-21

android:layout_marginEnd="111dp"

android:layout_marginBottom="582dp"

android:text="LOGIN PAGE"

android:textAlignment="center"

android:textColor="#100202"

android:textSize="36sp" />

<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="22dp"

android:layout_marginBottom="461dp"

android:ems="10"

android:hint="Enter Email"

android:inputType="textPersonName"

android:text=""

android:textSize="30sp" />

<EditText

android:id="@+id/passwordEditText"
Department of CSE, GEC Haveri Page 24
Mobile Application Development(18CSMP68) 2020-21

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentEnd="true"

android:layout_alignParentBottom="true"

android:layout_marginEnd="18dp"

android:layout_marginBottom="366dp"

android:ems="10"

android:hint="Enter Password"

android:inputType="textPassword"

android:textSize="30sp" />

<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="116dp"

android:layout_marginBottom="235dp"

android:text="LOGIN"

android:textSize="36sp" />

</RelativeLayout>

Department of CSE, GEC Haveri Page 25


Mobile Application Development(18CSMP68) 2020-21

LoginActivity.java

import .AppCompatActivity;

import .Intent;

import .Bundle;

import .View;

import .Button;

import .EditText;

import .Toast;

public class LoginActivity extends AppCompatActivity {

EditText emailEditText, passwordEditText;

Button loginBtn;

int counter=0;

@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
Department of CSE, GEC Haveri Page 26
Mobile Application Development(18CSMP68) 2020-21

public void onClick(View v) {

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

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

if (registeredEmail.equals(email) &&registeredPassword.equals(passwor

d)) {

Intent intent = new Intent(LoginActivity.this, LoginSuccessActivit

y.class);

startActivity(intent);

} else {

Toast.makeText(LoginActivity.this, "Invalid Credentials", Toast.LE

NGTH_SHORT).show();

counter--;
if(counter==0){
Toast.makeText(getBaseContext(),"Failed Login Attemptes",
Toast.LENGTH_LONG).show();
}

});

Department of CSE, GEC Haveri Page 27


Mobile Application Development(18CSMP68) 2020-21

III. Login Successful Activity


activity_login_success.xml

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

<TextView

android:id="@+id/textView2"

android:layout_width="307dp"

android:layout_height="216dp"

android:layout_alignParentEnd="true"

android:layout_alignParentBottom="true"

android:layout_marginEnd="67dp"

android:layout_marginBottom="413dp"

android:text="Login Successful"

android:textColor="#E91E63"

android:textSize="40dp" />

</RelativeLayout>

Department of CSE, GEC Haveri Page 28


Mobile Application Development(18CSMP68) 2020-21

LoginSuccessActivity.java (no changes made)

import .AppCompatActivity;

import .Bundle;

public class LoginSuccessActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_login_success);

} }

Department of CSE, GEC Haveri Page 29


Mobile Application Development(18CSMP68) 2020-21

OUTPUT:

Department of CSE, GEC Haveri Page 30


Mobile Application Development(18CSMP68) 2020-21

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.
(Save five images (jpg format) in the drawable folder. In this example one.jpg,
two.jpg,three.jpg, four.jpg and five.jpg images are saved in drawable folder.)

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="96dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="40dp"
android:layout_marginBottom="556dp"

Department of CSE, GEC Haveri Page 31


Mobile Application Development(18CSMP68) 2020-21

android:text="Changing Wallpaper"
android:textAlignment="center"
android:textColor="#970435"
android:textSize="36sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/button"
android:layout_width="280dp"
android:layout_height="86dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="55dp"
android:layout_marginBottom="373dp"
android:text="Click here to chnage wallpaper"
android:textSize="18sp" />

</RelativeLayout>

JAVA CODE:
import androidx.appcompat.app.AppCompatActivity;

import android.app.WallpaperManager;

import android.graphics.Bitmap;

Department of CSE, GEC Haveri Page 32


Mobile Application Development(18CSMP68) 2020-21

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;

public class MainActivity extends AppCompatActivity {

Button changewallpaper;

Timer mytimer;

Drawable drawable;

WallpaperManagerwpm;

int prev=1;

@Override

Department of CSE, GEC Haveri Page 33


Mobile Application Development(18CSMP68) 2020-21

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

mytimer = new Timer();

wpm = WallpaperManager.getInstance(this);

changewallpaper = findViewById(R.id.button);
changewallpaper.setOnClickListener(new View.OnClickListener() {

@Override public void onClick(View view) {

setWallpaper();

});

private void setWallpaper() {

mytimer.schedule(new TimerTask() {

@Override

public void run() {

if(prev==1) {

drawable = getResources().getDrawable(R.drawable.one);

prev = 2;

}
Department of CSE, GEC Haveri Page 34
Mobile Application Development(18CSMP68) 2020-21

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

Department of CSE, GEC Haveri Page 35


Mobile Application Development(18CSMP68) 2020-21

} catch (IOException e) {

e.printStackTrace();

},0,30000); } }

OUTPUT:

Department of CSE, GEC Haveri Page 36


Mobile Application Development(18CSMP68) 2020-21

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.

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="311dp"
android:layout_height="69dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="41dp"
android:layout_marginBottom="591dp"

Department of CSE, GEC Haveri Page 37


Mobile Application Development(18CSMP68) 2020-21

android:text="COUNTER APP"
android:textAlignment="center"
android:textColor="#120808"
android:textSize="36sp"
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="275dp"
android:layout_height="136dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="66dp"
android:layout_marginBottom="399dp"
android:text="Counter Value"
android:textAlignment="center"
android:textSize="36sp" />

<Button
android:id="@+id/btnStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
Department of CSE, GEC Haveri Page 38
Mobile Application Development(18CSMP68) 2020-21

android:layout_marginEnd="253dp"
android:layout_marginBottom="291dp"
android:text="START"
android:textSize="18sp" />

<Button
android:id="@+id/btnSTOP"
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="289dp"
android:text="STOP"
android:textSize="18sp" />

</RelativeLayout>

JAVA CODE:
package com.example.a5a;

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;
Department of CSE, GEC Haveri Page 39
Mobile Application Development(18CSMP68) 2020-21

public class MainActivity extends AppCompatActivity {

Button btnstart, btnstop;

TextViewtxtcounter;

int i = 1;

Handler customHandler = new Handler();

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

txtcounter = findViewById(R.id.textView1);

btnstart = findViewById(R.id.btn_start);

btnstop = findViewById(R.id.btn_stop);

btnstart.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

customHandler.postDelayed(updateTimerThread,0);

});

btnstop.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

customHandler.removeCallbacks(updateTimerThread);

}
Department of CSE, GEC Haveri Page 40
Mobile Application Development(18CSMP68) 2020-21

});

private final Runnable updateTimerThread = new Runnable() {

@Override

public void run() {

txtcounter.setText(""+i);

customHandler.postDelayed(this,1000);

i++;

};

OUTPUT:

Department of CSE, GEC Haveri Page 41


Mobile Application Development(18CSMP68) 2020-21

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.

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="352dp"
android:layout_height="56dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"

Department of CSE, GEC Haveri Page 42


Mobile Application Development(18CSMP68) 2020-21

android:layout_marginEnd="21dp"
android:layout_marginBottom="617dp"
android:text="Parsing Application"
android:textAlignment="center"
android:textColor="#071CA8"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<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="251dp"
android:layout_marginBottom="518dp"
android:onClick="parsexml"
android:text="Parse XML" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
Department of CSE, GEC Haveri Page 43
Mobile Application Development(18CSMP68) 2020-21

android:layout_alignParentBottom="true"
android:layout_marginEnd="50dp"
android:layout_marginBottom="516dp"
android:onClick="parseJSON"
android:text="PARSE JSON" />

<TextView
android:id="@+id/display"
android:layout_width="342dp"
android:layout_height="426dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="31dp"
android:layout_marginBottom="54dp"
android:textColor="#5D0C6A"
android:textSize="24sp"
android:textStyle="italic" />

</RelativeLayout>

JAVA CODE:

package com.example.parseapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

Department of CSE, GEC Haveri Page 44


Mobile Application Development(18CSMP68) 2020-21

import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

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.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

public class MainActivity extends AppCompatActivity {


TextView display;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
display=findViewById(R.id.display);
}
Department of CSE, GEC Haveri Page 45
Mobile Application Development(18CSMP68) 2020-21

public void parsexml(View v){


try {
InputStream is=getAssets().open("city.xml");
DocumentBuilderFactory
documentBuilderFactory=DocumentBuilderFactory.newInstance();
DocumentBuilder
documentBuilder=documentBuilderFactory.newDocumentBuilder();
Document document=documentBuilder.parse(is);
StringBuilder stringBuilder=new StringBuilder();
stringBuilder.append("XML DATA");
stringBuilder.append("\n----------");
NodeList nodeList=document.getElementsByTagName("place");
for (int i=0; i<nodeList.getLength(); i++)
{
Node node=nodeList.item(i);
if (node.getNodeType()==Node.ELEMENT_NODE)
{
Element element=(Element)node;
stringBuilder.append("\nName:").append(getValue("name",element));
stringBuilder.append("\nLatitude:").append(getValue("lat",element));

stringBuilder.append("\nLongitude:").append(getValue("long",element));

stringBuilder.append("\nTemperature:").append(getValue("temperature",element));

stringBuilder.append("\nHumidity:").append(getValue("humidity",element));
stringBuilder.append("\n-------");
Department of CSE, GEC Haveri Page 46
Mobile Application Development(18CSMP68) 2020-21

}
}
display.setText(stringBuilder.toString());
} catch (Exception e){
e.printStackTrace();
Toast.makeText(MainActivity.this,"Error Parsing
XML",Toast.LENGTH_SHORT).show();
}
}
public void parseJSON(View v){
String json;
StringBuilder stringBuilder=new StringBuilder();
try{
InputStream is=getAssets().open("city.json");
int size=is.available();
byte[]buffer=new byte[size];
is.read(buffer);
json=new String(buffer,StandardCharsets.UTF_8);
JSONArray jsonArray=new JSONArray(json);
stringBuilder.append("JSON DATA");
stringBuilder.append("\n-------");
for (int i=0;i<jsonArray.length();i++){
JSONObject jsonObject=jsonArray.getJSONObject(i);
stringBuilder.append("\nName:").append(jsonObject.getString("name"));
stringBuilder.append("\nLatitude:").append(jsonObject.getString("lat"));

stringBuilder.append("\nLongitude:").append(jsonObject.getString("long"));
Department of CSE, GEC Haveri Page 47
Mobile Application Development(18CSMP68) 2020-21

stringBuilder.append("\nTemperature:").append(jsonObject.getString("temp"));

stringBuilder.append("\nHumidity:").append(jsonObject.getString("humi"));
stringBuilder.append("\n--------");
}
display.setText(stringBuilder.toString());
is.close();
} catch (Exception e){
e.printStackTrace();
Toast.makeText(MainActivity.this,"Error in parsing JSON
data",Toast.LENGTH_SHORT).show();
}
}
private String getValue(String tag, Element element){
return
element.getElementsByTagName(tag).item(0).getChildNodes().item(0).getNodeV
alue();
}
}

Department of CSE, GEC Haveri Page 48


Mobile Application Development(18CSMP68) 2020-21

OUTPUT:

Department of CSE, GEC Haveri Page 49


Mobile Application Development(18CSMP68) 2020-21

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:

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

android:layout_height="wrap_content"

android:layout_alignParentEnd="true"

android:layout_alignParentBottom="true"

android:layout_marginEnd="72dp"

Department of CSE, GEC Haveri Page 50


Mobile Application Development(18CSMP68) 2020-21

android:layout_marginBottom="582dp"

android:text="Text2Speech"

android:textAlignment="center"

android:textColor="#0E0101"

android:textSize="36sp"

android:textStyle="bold|italic"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintRight_toRightOf="parent"

app:layout_constraintTop_toTopOf="parent" />

<EditText

android:id="@+id/editText"

android:layout_width="283dp"

android:layout_height="67dp"

android:layout_alignParentEnd="true"

android:layout_alignParentBottom="true"

android:layout_marginEnd="63dp"

android:layout_marginBottom="361dp"

android:ems="10"

android:hint="Enter the text"

android:inputType="textPersonName"

android:text=""
Department of CSE, GEC Haveri Page 51
Mobile Application Development(18CSMP68) 2020-21

android:textSize="30sp"

android:textStyle="italic" />

<Button

android:id="@+id/button"

android:layout_width="290dp"

android:layout_height="wrap_content"

android:layout_alignParentEnd="true"

android:layout_alignParentBottom="true"

android:layout_marginEnd="66dp"

android:layout_marginBottom="205dp"

android:onClick="convert"

android:text="Convert to Speech"

android:textSize="18sp" />

</RelativeLayout>

JAVA CODE:

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.speech.tts.TextToSpeech;

import android.view.View;

Department of CSE, GEC Haveri Page 52


Mobile Application Development(18CSMP68) 2020-21

import android.widget.EditText;

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

Department of CSE, GEC Haveri Page 53


Mobile Application Development(18CSMP68) 2020-21

t1.speak(tospeak,TextToSpeech.QUEUE_FLUSH,null);

OUTPUT:

Department of CSE, GEC Haveri Page 54


Mobile Application Development(18CSMP68) 2020-21

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:

<?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="244dp"
android:layout_height="wrap_content"

Department of CSE, GEC Haveri Page 55


Mobile Application Development(18CSMP68) 2020-21

android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="94dp"
android:layout_marginBottom="628dp"
android:text="Call Application"
android:textAlignment="center"
android:textColorLink="#100808"
android:textSize="30sp"
android:textStyle="bold|italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<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="286dp"
android:layout_marginBottom="403dp"
android:onClick="inputNumber"
android:text="1" />

<Button
android:id="@+id/button2"
Department of CSE, GEC Haveri Page 56
Mobile Application Development(18CSMP68) 2020-21

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="177dp"
android:layout_marginBottom="406dp"
android:onClick="inputNumber"
android:text="2" />

<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="63dp"
android:layout_marginBottom="406dp"
android:onClick="inputNumber"
android:text="3" />

<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="285dp"
Department of CSE, GEC Haveri Page 57
Mobile Application Development(18CSMP68) 2020-21

android:layout_marginBottom="342dp"
android:onClick="inputNumber"
android:text="4" />

<Button
android:id="@+id/button5"
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="338dp"
android:onClick="inputNumber"
android:text="5" />

<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="59dp"
android:layout_marginBottom="335dp"
android:onClick="inputNumber"
android:text="6" />

<Button
Department of CSE, GEC Haveri Page 58
Mobile Application Development(18CSMP68) 2020-21

android:id="@+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="287dp"
android:layout_marginBottom="276dp"
android:onClick="inputNumber"
android:text="7" />

<Button
android:id="@+id/button8"
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="276dp"
android:onClick="inputNumber"
android:text="8" />

<Button
android:id="@+id/button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
Department of CSE, GEC Haveri Page 59
Mobile Application Development(18CSMP68) 2020-21

android:layout_marginEnd="62dp"
android:layout_marginBottom="276dp"
android:onClick="inputNumber"
android:text="9" />

<Button
android:id="@+id/button10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="286dp"
android:layout_marginBottom="206dp"
android:onClick="inputNumber"
android:text="#" />

<Button
android:id="@+id/button11"
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="206dp"
android:onClick="inputNumber"
android:text="0" />

Department of CSE, GEC Haveri Page 60


Mobile Application Development(18CSMP68) 2020-21

<Button
android:id="@+id/button12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="64dp"
android:layout_marginBottom="208dp"
android:onClick="inputNumber"
android:text="*" />

<EditText
android:id="@+id/phoneNumberEditText"
android:layout_width="305dp"
android:layout_height="64dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="55dp"
android:layout_marginBottom="526dp"
android:ems="10"
android:hint="Enter Phone NUmber"
android:inputType="textPersonName" />

<Button
android:id="@+id/saveBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Department of CSE, GEC Haveri Page 61
Mobile Application Development(18CSMP68) 2020-21

android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="282dp"
android:layout_marginBottom="132dp"
android:text="save" />

<Button
android:id="@+id/callBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="174dp"
android:layout_marginBottom="132dp"
android:text="call" />

<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="70dp"
android:layout_marginBottom="134dp"
android:text="clear" />

</RelativeLayout>
Department of CSE, GEC Haveri Page 62
Mobile Application Development(18CSMP68) 2020-21

JAVA CODE:

package com.example.callapplication;

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);
clearBtn=findViewById(R.id.clearBtn);
callBtn=findViewById(R.id.callBtn);
saveBtn=findViewById(R.id.saveBtn);

Department of CSE, GEC Haveri Page 63


Mobile Application Development(18CSMP68) 2020-21

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

}
Department of CSE, GEC Haveri Page 64
Mobile Application Development(18CSMP68) 2020-21

public void inputNumber(View v){


Button btn=(Button)v;
String digit=btn.getText().toString();
String phoneNumber= phoneNumberEditText.getText().toString();
phoneNumberEditText.setText(phoneNumber+digit);
}
}

OUTPUT:

Department of CSE, GEC Haveri Page 65

You might also like