0% found this document useful (0 votes)
47 views

Mad Lab Manual 18csmp68 1

The document is a laboratory manual for a Mobile Application Development course. It contains instructions for 8 programming assignments to create various Android applications using activities, controls, parsing XML and JSON files. It includes the vision, mission, program outcomes and objectives of the department and course. The first assignment asks students to create a visiting card application with a logo, name, employee details and a horizontal line.

Uploaded by

Pooja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Mad Lab Manual 18csmp68 1

The document is a laboratory manual for a Mobile Application Development course. It contains instructions for 8 programming assignments to create various Android applications using activities, controls, parsing XML and JSON files. It includes the vision, mission, program outcomes and objectives of the department and course. The first assignment asks students to create a visiting card application with a logo, name, employee details and a horizontal line.

Uploaded by

Pooja
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/ 30

Mobile Application Development Laboratory

Manual

6th Semester

18CSMP68

Name: _______________________________________________________

USN: ________________________________________________________
Vision of the Department
Educating Students to Engineer Information Science and Technology for Advancing the Knowledge as to best
serve the Real world.
Mission of the Department
M1: Focusing on Fundamentals and Applied aspects in both Information Science Theory and Programming
practices.
M2: Training comprehensively and encouraging R&D culture in trending areas of Information Technology.
M3: Collaborating with premier Institutes and Industries to nurture Innovation and learning, in cutting edge
Information Technology.
M4: Preparing the students who are much Sought-after, Productive and Well-respected for their work
culture having Lifelong Learning practice.
M5: Promoting ethical and moral values among the students so as to enable them emerge as responsible
professionals.
Program Outcomes
PO1: Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals,
and an engineering specialization to the solution of complex engineering problems
PO2: Problem analysis: Identify, formulate, research literature, and analyze complex engineering problems
reaching substantiated conclusions using first principles of mathematics, natural sciences, and engineering
sciences.
PO3: 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.
PO4: 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.
PO5: Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modelling to complex engineering activities with an
understanding of the limitations.
PO6: 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.
PO7: 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.
PO8: Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the
engineering practice
PO9: Individual and team work: Function effectively as an individual, and as a member or leader in diverse
teams, and in multidisciplinary settings
PO10: 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
PO11: 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
PO12: 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
Program Educational Objectives
PEO1: Engage in Successful professional career in Information Science and Technology.
PEO2: Pursue higher studies and research to advance the knowledge for Solving Contemporary Problems in
IT industry.
PEO3: Adapt to a constantly changing world through Professional Development and Sustained Learning.
PEO4: Exhibit professionalism and team work with social concern.
PEO5: Develop Leadership and Entrepreneurship Skills by incorporating Organizational goals.
Program Specific Outcomes
PSO1: Apply the knowledge of data structures, database systems, system programming, networking, web
development and AI & ML techniques in engineering the software.
PSO2: Exhibit solid foundations and advancements in developing software / hardware systems for solving
contemporary problems.
Contents
Exp. Page
Problem Statement
No. No.
Part A
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
1. the center. Information like the name of the employee, job title, phone number, address, email, 1
fax and the website address is to be displayed. Insert a horizontal line between the job title and
the phone number.
Develop an Android application using controls like Button, TextView, EditText for designing
2. a calculator having basic functionality like Addition, Subtraction, Multiplication, and 4
Division.
Create a SIGN Upton activity with Username and Password. Validation of password should
3. 8
happen
Develop an application to set an image as wallpaper. On click of a button, the wallpaper image
4. 12
should start to change randomly every 30 seconds.
Write a program to create an activity with two buttons START and STOP. On pressing of the
5. START button, the activity must start the counter by displaying the numbers from One and the 14
counter must keep on counting until the STOP button is pressed. Display the counter
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
6. 16
parse the XML and JSON files which when clicked should display the data in their respective
layouts side by side.
Develop a simple application with one Edit Text so that the user can write some text in it.
7. 19
Create a button called “Convert Text to Speech” that converts the user input text into voice.
Create an activity like a phone dialer with CALL and SAVE buttons. On pressing the CALL
8. button, it must call the phone number and on pressing the SAVE button it must save the 21
number to the phone contacts.
Part B 23
Viva Voce 26
MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68
Program-1
Create an application to design a Visiting Card. The Visiting card should have a company logo at the
top right corner. The company name should be displayed in Capital letters, aligned to the center.
Information like the name of the employee, job title, phone number, address, email, fax and the
website address is to be displayed. Insert a horizontal line between the job title and the phone number.

XML-CODE
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="17dp"
android:layout_marginLeft="17dp"
android:layout_marginTop="17dp"
android:layout_marginEnd="244dp"
android:layout_marginRight="244dp"
android:layout_marginBottom="486dp"
android:text="SJCIT"
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"
SJCIT, Department of Information Science and Engineering 1
MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68
android:layout_marginEnd="-14dp"
android:layout_marginRight="-14dp"
android:layout_marginBottom="481dp"
app:srcCompat="@drawable/logo" />

<View
android:id="@+id/view"
android:layout_width="wrap_content"
android:layout_height="4dp"
android:layout_alignParentBottom="true"
android:background="#4444"
android:layout_marginBottom="466dp" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="117dp"
android:layout_marginRight="117dp"
android:layout_marginBottom="394dp"
android:text="Amar Akbar Anthony"
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-ISE"
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"
SJCIT, Department of Information Science and Engineering 2
MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68
android:text="Ph No: 9988776655"
android:textSize="20dp" />

<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="229dp"
android:text="PB No. 20, BB Road, Chickballapur-562 101"
android:textSize="20dp" />

<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="44dp"
android:layout_marginRight="44dp"
android:layout_marginBottom="189dp"
android:text="Email: [email protected]"
android:textSize="20dp" />
</RelativeLayout>
JAVA-CODE

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
OUTPUT:

SJCIT, Department of Information Science and Engineering 3


MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68
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"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="98dp"
android:layout_marginBottom="653dp"
android:text="SIMPLE CALCI"
android:textSize="38dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.042" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
SJCIT, Department of Information Science and Engineering 4
MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="115dp"
android:layout_marginBottom="547dp"
android:ems="10"
android:hint="Enter the First Number"
android:inputType="textPersonName"
android:text="" />

<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="111dp"
android:layout_marginBottom="455dp"
android:ems="10"
android:inputType="textPersonName"
android:hint="Enter the Second Number"
android:text="" />

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="203dp"
android:layout_marginBottom="350dp"
android:text="0"
android:textSize="40dp" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="274dp"
android:layout_marginBottom="237dp"
android:onClick="doAdd"
android:text="ADD" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
SJCIT, Department of Information Science and Engineering 5
MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68
android:layout_marginEnd="68dp"
android:layout_marginBottom="233dp"
android:onClick="doSub"
android:text="SUB" />

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="277dp"
android:layout_marginBottom="115dp"
android:onClick="doMul"
android:text="MUL" />

<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="63dp"
android:layout_marginBottom="104dp"
android:onClick="doDiv"
android:text="DIV" />

</RelativeLayout>

JAVA-CODE
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

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

SJCIT, Department of Information Science and Engineering 6


MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68
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);
}
}

OUTPUT:

SJCIT, Department of Information Science and Engineering 7


MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68
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.

//SignUpActivity.java
import.AppCompatActivity;
import.Intent;
import.Bundle;
import.View;
import.Button;
import.EditText;
import.Toast;
import.Pattern;
public class SignUpActivity extends AppCompatActivity {
EditText emailEditText, passwordEditText;
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)) {
SJCIT, Department of Information Science and Engineering 8
MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68
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);
}
});
}

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;
}
// Returns false if password doesn't contain a special character
if (!specialCharacter.matcher(password).matches()) {
return false;
}
return true;
}
}

//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;
@Override
protected void onCreate(Bundle savedInstanceState) {
SJCIT, Department of Information Science and Engineering 9
MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
emailEditText = findViewById(R.id.emailEditText);
passwordEditText = findViewById(R.id.passwordEditText);
loginBtn = findViewById(R.id.loginBtn);
String registeredEmail = getIntent().getStringExtra("email");
String registeredPassword = getIntent().getStringExtra("password");
loginBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String email = emailEditText.getText().toString();
String password = passwordEditText.getText().toString();
if(registeredEmail.equals(email)&&
registeredPassword.equals(password))
{
Intent intent = new Intent(LoginActivity.this, LoginSuccessActivity.class);
startActivity(intent);
}
else
{
Toast.makeText(LoginActivity.this, "Invalid Credentials", Toast.LE
NGTH_SHORT).show();
}
}
});
}
}

//LoginSuccessActivity.java
import .AppCompatActivity;
import .Bundle;
public class LoginSuccessActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_success);
}
}

SJCIT, Department of Information Science and Engineering 10


MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68
OUTPUT:

SJCIT, Department of Information Science and Engineering 11


MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68
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.

//First, create the android application as discussed in “Create your First Android Application”. Copy the
//images and save the images in the drawable folder. Following is the content of the modified
//res/layout/activity_main.xml.
//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.
//MainActivity.java package com.example.lab4a;

import androidx.appcompat.app.AppCompatActivity;
import android.app.WallpaperManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
public class MainActivity extends AppCompatActivity {
Button changewallpaper;
Timer mytimer;
Drawable drawable;
WallpaperManager wpm;
int prev=1;
@Override
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
SJCIT, Department of Information Science and Engineering 12
MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68
public void run() {
if(prev==1) {
drawable = getResources().getDrawable(R.drawable.one);
prev = 2;
}
else if(prev==2) {
drawable = getResources().getDrawable(R.drawable.two);
prev=3;
}
else if(prev==3) {
drawable = getResources().getDrawable(R.drawable.three);
prev=4;
}
else if(prev==4) {
drawable = getResources().getDrawable(R.drawable.four);
prev=5;
}
else if(prev==5) {
drawable = getResources().getDrawable(R.drawable.five);
prev=1;
}

Bitmap wallpaper = ((BitmapDrawable)drawable).getBitmap();


try {
wpm.setBitmap(wallpaper);
} catch (IOException e) {
e.printStackTrace();
}
}
},0,30000); } }

OUTPUT:

SJCIT, Department of Information Science and Engineering 13


MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68
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.

//MainActivity.java
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;

public class MainActivity extends AppCompatActivity {


Button btnstart, btnstop;
TextView txtcounter;
int i = 1;
Handler customHandler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
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);
}
});
}

SJCIT, Department of Information Science and Engineering 14


MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68
private final Runnable updateTimerThread = new Runnable() {
@Override
public void run() {
txtcounter.setText(""+i);
customHandler.postDelayed(this,1000);
i++;
}
};
}

OUTPUT:

SJCIT, Department of Information Science and Engineering 15


MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68

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.

//MainActivity.java
import android.os.Bundle;
import android.util.Log;
import android.util.Xml;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
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 org.xml.sax.SAXException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

public class MainActivity extends AppCompatActivity {


Button parseXmlBtn, parseJsonBtn;
TextView displayTextView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

SJCIT, Department of Information Science and Engineering 16


MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68
parseJsonBtn = findViewById(R.id.parseJsonBtn);
parseXmlBtn = findViewById(R.id.parseXmlBtn);

displayTextView = findViewById(R.id.displayTextView);

parseXmlBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(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----------");
}
}
displayTextView.setText(stringBuilder.toString());

} catch (Exception e) {
e.printStackTrace();
Toast.makeText(MainActivity.this, "Error Parsing XML", Toast.LENGTH_SHORT).show();
}
}
});

parseJsonBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(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);

SJCIT, Department of Information Science and Engineering 17


MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68
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"));
stringBuilder.append("\nTemperature:").append(jsonObject.getString("temperature"));
stringBuilder.append("\nHumidity: ").append(jsonObject.getString("humidity"));
stringBuilder.append("\n----------");
}
displayTextView.setText(stringBuilder.toString());
is.close();
} catch (IOException | JSONException e) {
e.printStackTrace();
Toast.makeText(MainActivity.this, "Error in parsing JSON data from!",Toast.LENGTH_SHORT)
.show();
}
}
});
}

private String getValue(String tag, Element element) {


return element.getElementsByTagName(tag).item(0).getChildNodes().item(0).getNodeValue();
}
}

SJCIT, Department of Information Science and Engineering 18


MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68

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.

//MainActivity.java

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import java.util.Locale;

public class MainActivity extends AppCompatActivity {

TextToSpeech t1;
EditText e1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e1 = (EditText)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();
Toast.makeText(getBaseContext(),tospeak,Toast.LENGTH_LONG).show();
t1.speak(tospeak,TextToSpeech.QUEUE_FLUSH,null);
}
}

SJCIT, Department of Information Science and Engineering 19


MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68

OUTPUT:

SJCIT, Department of Information Science and Engineering 20


MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68

Program-8
Create an activity like a phone dialler 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.

//MainActivity.java

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

clearBtn.setOnClickListener(new View.OnClickListener() {
SJCIT, Department of Information Science and Engineering 21
MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68
@Override
public void onClick(View v) {
phoneNumberEditText.setText("");
}
});

callBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String phoneNumber = phoneNumberEditText.getText().toString();
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + phoneNumber));
startActivity(intent);
}
});

saveBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String phoneNumber = phoneNumberEditText.getText().toString();
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
intent.putExtra(ContactsContract.Intents.Insert.PHONE, phoneNumber);
startActivity(intent);
}
});
}

public void inputNumber(View v) {


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

SJCIT, Department of Information Science and Engineering 22


MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68

PART-B:
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).
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 Eveningor Night. Trigger an alarm based on the Date and Time of the Day and
display the Medicine Name.

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

SJCIT, Department of Information Science and Engineering 23


MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68

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.

4. Write a program to create an activity having a Text box, and also Save, Open and Create
buttons. The user has to write some text in the Text box. On pressing the Create button the text
should be saved as a text file in MkSDcard. On subsequent changes to the text, the Save button
should be pressed to store the latest content to the same file. On pressing the Open button, it
should display the contents from the previously stored files in the Text box. If the user tries to
save the contents in the Textbox to a file without creating it, then a toast message has to be
displayed saying “First Create a File”.

5. Create an application to demonstrate a basic media playerthat 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.

SJCIT, Department of Information Science and Engineering 24


MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68

6. Develop an application to demonstrate the use of Asynchronous tasks in android. The


asynchronous task should implement the functionality of a simple moving banner. On pressing
the Start Task button, the banner message should scrollfrom right to left. On pressing the Stop
Task button, the banner message should stop.Let the banner message be “Demonstration of
Asynchronous Task”.

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.

8. Create an AIDL service that calculates Car Loan EMI. The formula to calculate EMI is E = P
* (r(1+r)n )/((1+r)n -1) where E = The EMI payable on the car loan amount P = The Car loan
Principal Amount r = The interest rate value computed on a monthly basis n = The loan tenure
in the form of months The down payment amount has to be deducted from the principal
amount paid towards buying the Car. Develop an application that makes use of this AIDL
service to calculate the EMI. This application should have four EditText to read the
PrincipalAmount, Down Payment, Interest Rate, Loan Term (in months) and a button named
as “Calculate Monthly EMI”. On click of this button, the result should be shown in a
TextView. Also, calculate the EMI by varying the Loan Term and Interest Rate values.

SJCIT, Department of Information Science and Engineering 25


MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68

Viva Voce Questions


1) What is Android?
2) What Is the Google Android SDK?
3) What is the Android Architecture?
4) Describe the Android Framework.
5) What is AAPT?
6) What is the importance of having an emulator within the Android environment?
7) What is the use of an activityCreator?
8) Describe Activities.
9) What are Intents?
10) Differentiate Activities from Services.
11) What items are important in every Android project?
12) What is the importance of XML-based layouts?
13) What are containers?
14) What is Orientation?
15) What is the importance of Android in the mobile market?
16) What do you think are some disadvantages of Android?
17) What is adb?
18) What are the four essential states of an activity?
19) What is ANR?
20) Which elements can occur only once and must be present?
21) How are escape characters used as attribute?
22) What is the importance of settings permissions in app development?
23) What is the function of an intent filter?
24) Enumerate the three key loops when monitoring an activity
25) When is the onStop() method invoked?
26) Is there a case wherein other qualifiers in multiple resources take precedence over locale?
27) What are the different states wherein a process is based?
28) How can the ANR be prevented?
29) What role does Dalvik play in Android development?
30) What is the AndroidManifest.xml?
31) What is the proper way of setting up an Android-powered device for app development?
32) Enumerate the steps in creating a bounded service through AIDL.
33) What is the importance of Default Resources?
34) When dealing with multiple resources, which one takes precedence?
35) When does ANR occur?
36) What is AIDL?
37) What data types are supported by AIDL?
38) What is a Fragment?
39) What is a visible activity?
40) When is the best time to kill a foreground activity?
41) Is it possible to use or add a fragment without using a user interface?
42) How do you remove icons and widgets from the main screen of the Android device?
43) What are the core components under the Android application architecture?
44) What composes a typical Android application project?
45) What is a Sticky Intent?
46) Do all mobile phones support the latest Android operating system?
47) What is portable wi-fi hotspot?
SJCIT, Department of Information Science and Engineering 26
MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68
48) What is an action?
49) What is the difference between a regular bitmap and a nine-patch image?
50) What language is supported by Android for application development?

SJCIT, Department of Information Science and Engineering 27

You might also like