Mobile Application Laboratory Manual (Vtu)
Mobile Application Laboratory Manual (Vtu)
NAME :
............................................................................................................................. ................................................................................................................................................................................................................................................................ ..........................................
SECTION : ...........................................................................................................................................................................................
VISION
USN :
AND MISSION OF INSTITUTION
VISION AND MISSION OF INSTITUTION
Vision
Building RNSIT into a World Class Institution
Mission
To impart high quality education in Engineering, Technology and Management with a
Difference, Enabling Students to Excel in their Career by
1. Attracting quality Students and preparing them with a strong foundation in fundamentals so as to
achieve distinctions in various walks of life leading to outstanding contributions
2. Imparting value based, need based, choice based and skill based professional education to the
aspiring youth and carving them into disciplined, World class Professionals with social
responsibility
3. Promoting excellence in Teaching, Research and Consultancy that galvanizes academic
consciousness among Faculty and Students
4. Exposing Students to emerging frontiers of knowledge in various domains and make them
suitable for Industry, Entrepreneurship, Higher studies, and Research & Development
5. Providing freedom of action and choice for all the Stake holders with better visibility
Vision
Preparing better computer professionals for a real world
Mission
The Department of Computer Science and Engineering will make every effort to promote an
intellectual and an ethical environment in which the strengths and skills of Computer
Professionals will flourish by
1. Imparting Solid foundations and Applied aspects in both Computer Science Theory and
Programming practices
2. Providing Training and encouraging R&D and Consultancy Services in frontier areas of
Computer Science with a Global outlook
3. Fostering the highest ideals of Ethics, Values and creating Awareness on the role of Computing
in Global Environment
4. Educating and preparing the graduates, highly Sought-after, Productive, and Well-respected for
their work culture
5. Supporting and inducing Lifelong Learning practice
[DOCUMENT TITLE]
Mobile Application Development Laboratory- 18CSMP68
INTERNAL EVALUATION SHEET
10 10 10 10 40
c. Result and Meticulousdocumentation and Acceptable documentation shown Documentation does not
documentation all conditions are taken care (3) (2) take care all conditions
(3 marks) (1)
Sl.
Parameters Excellent Good Needs Improvement
No.
a. Design, implementation Program follows syntax and Program has few logical Syntax and semantics
and demonstration semantics of the programming errors, moderately of programming is not
(5 marks) language. Demonstrates the demonstrates all possible clear (1)
complete knowledge of the concepts implemented in
program written (5) programs (3)
b. Result and All test cases are successful, all Moderately debugs the Test cases are not taken
documentation errors are debugged with own programs , few test case are care , unable to debug
(5 marks) practical knowledge and clear unsuccessful and Partial the errors and no proper
documentation according to the documentation documentation (1)
guidelines (5) (3)
TEST-1
TEST-2 𝟒𝟎 𝟏𝟎
Write
Date of Exen. Viva Total Teacher
Week # Additional programs up
Execution (10) (10) 30 Signature
(10)
Total
Marks 𝟐𝟒𝟎 𝟑𝟎 𝟏𝟎
TITLE OF THE
PROJECT
TEAM MEMBERS
1
2 𝟒𝟎 𝟏𝟎
REMARKS
D: RECORD (10) 𝟒𝟎
We have developed this comprehensive laboratory manual on Mobile Application Development with
two primary objectives: To make the students comfortable with basic layout design in application
development and to train them in evolving as an efficient Android Developer by strengthening their
programming abilities.
The manual comprises of procedure for configuration of Android Studio followed by programming
solutions with expected output layouts.
Our profound and sincere efforts will be fruitful only when students acquire the extensive knowledge
by reading this manual and apply the concepts learnt apart from the requirements specified in C
Programming Laboratory as prescribed by VTU, Belagavi.
Department of CSE
Mobile Application Development Laboratory( 18CSMP68)
[DOCUMENT TITLE]
SYLLABUS
MOBILE APPLICATION DEVELOPMENTLABORATORY
Subject Code: 18CSMP68 IA Marks: 40
Lab Experiments:
1. The installation procedure of the Android Studio/Java software must be demonstrated
and carried out in groups.
2. Students should use the latest version of Android Studio/Java/ Kotlin to execute these
programs. Diagrams given are for representational purposes only, students are
expected to improvise on them.
3. Part B programs should be developed as an application and are to be demonstrated as
a mini project in a group by adding extra features or the students can also develop
their application and demonstrate it as a mini-project. (Projects/programs are not
limited to the list given in Part B).
PART A
Program 1
Create an application to design a Visiting Card. The Visiting card should have a company logo
at the top right corner. The company name should be displayed in Capital letters, aligned to the
center. Information like the name of the employee, job title, phone number, address, email, fax
and the website address is to be displayed. Insert a horizontal line between the job title and the
phone number.
[DOCUMENT TITLE]
Program 2
Develop an Android application using controls like Button, TextView, EditText for designing a
Calculator having basic functionality like Addition, Subtraction, Multiplication, and Division.
Program 3
Create a SIGN Up activity with Username and Password. Validation of password should
happen based on the following rules:
• Password should contain uppercase and lowercase letters.
• Password should contain letters and numbers.
• Password should contain special characters.
• Minimum length of the password (the default value is 8).
On successful SIGN UP proceed to the next Login activity. Here the user should SIGN IN
using the Username and Password created during signup activity. If the Username and
Password are matched then navigate to the next activity which displays a message saying
“Successful Login” or else display a toast message saying “Login Failed”. The user is given
only two attempts and after that display a toast message saying “Failed Login Attempts” and
disable the SIGN IN button. Use Bundle to transfer information from one activity to another
[DOCUMENT TITLE]
Program 4
Develop an application to set an image as wallpaper. On click of a button, the wallpaper image
should start to change randomly every 30 seconds.
Program 5
Write a program to create an activity with two buttons START and STOP. On Pressing of the
START button, the activity must start the counter by displaying the numbers from One and the
counter must keep on counting until the STOP button is pressed. Display the counter value in a
TextView control.
Program 6
Create two files of XML and JSON type with values for City_Name, Latitude, Longitude,
Temperature, and Humidity. Develop an application to create an activity with two buttons to
parse the XML and JSON files which when clicked should display the data in their respective
layouts side by side.
[DOCUMENT TITLE]
Program 7
Develop a simple application with one Edit Text so that the user can write some text in it.
Create a button called “Convert Text to Speech” that converts the user input text into voice.
Program 8
Create an activity like a phone dialer with CALL and SAVE buttons. On pressing the CALL
button, it must call the phone number and on pressing the SAVE button it must save the
number to the phone contacts
[DOCUMENT TITLE]
PART B
Program 1
Write a program to enter Medicine Name, Date and Time of the Day as input from the user and
store it in the SQLite database. Input for Time of the Day should be either Morning or
Afternoon or Evening or Night. Trigger an alarm based on the Date and Time of the Day and
display the Medicine Name.
Program 2
Develop a content provider application with an activity called “Meeting Schedule” which takes
Date, Time and Meeting Agenda as input from the user and store this information into the
SQLite database. Create another application with an activity called “Meeting Info” having
DatePicker control, which on the selection of a date should display the Meeting Agenda
information for that particular date, else it should display a toast message saying “No Meeting
on this Date”.
[DOCUMENT TITLE]
Program 3
Create an application to receive an incoming SMS which is notified to the user. On clicking
this
SMS notification, the message content and the number should be displayed on the screen. Use
appropriate emulator control to send the SMS message to your application
Program 4
Write a program to create an activity having a Text box, and also Save, Open and Create
buttons. The user has to write some text in the Text box. On pressing the Create button the text
should be saved as a text file in MkSDcard. On subsequent changes to the text, the Save button
should be pressed to store the latest content to the same file. On pressing the Open button, it
should display the contents from the previously stored files in the Text box. If the user tries to
save the contents in the Textbox to a file without creating it, then a toast message has to be
displayed saying “FirstCreate a File”.
[DOCUMENT TITLE]
Program 5
Create an application to demonstrate a basic media player that allows the user to Forward,
Backward, Play and Pause an audio. Also, make use of the indicator in the seek bar to move the
audio forward or backward as required.
Program 6
Program 7
Develop an application that makes use of the clipboard framework for copying and pasting of
the text. The activity consists of two EditText controls and two Buttons to trigger the copy and
paste functionality.
[DOCUMENT TITLE]
Program 8
Create an AIDL service that calculates Car Loan EMI. The formula to calculate EMI is
E = P * (r(1+r)n)/((1+r)n-1)
where
E = The EMI payable on the car loan amount
P = The Car loan Principal Amount
r = The interest rate value computed on a monthly basis
n = The loan tenure in the form of months
The down payment amount has to be deducted from the principal amount paid towards buying
the Car. Develop an application that makes use of this AIDL service to calculate the EMI. This
application should have four EditText to read the Principal Amount, Down Payment, Interest
Rate, Loan Term (in months) and a button named as “Calculate Monthly EMI”. On click of this
button, the result should be shown in a TextView. Also, calculate the EMI by varying the Loan
Term and Interest Rate values.
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 isto be displayed. Insert a horizontal line between the job title and the
phone number.
MainActivity.java
package com.example.visitingcard;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Activity_main.xml
Page 1
Mobile Application Development Lab (18CSMP68)
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp">
<TextView
android:layout_width="390dp"
android:layout_height="89dp"
android:layout_marginLeft="20dp"
android:capitalize="sentences"
android:fontFamily="casual"
android:foregroundGravity="center"
android:paddingLeft="10dp"
android:paddingRight="20dp"
android:text="\nRNS INSTITUTE OF TECHNOLOGY\n"
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
android:textColor="#06114E"
android:textSize="20sp"
android:textStyle="bold|italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="350dp"
android:layout_marginTop="30dp"
android:layout_marginRight="20dp"
android:src="@drawable/icon3" />
</RelativeLayout>
<TableRow
android:id="@+id/hr"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#CE851414"
android:paddingTop="10dp"
android:paddingBottom="10dp"></TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
Page 2
Mobile Application Development Lab (18CSMP68)
android:fontFamily="serif-monospace"
android:paddingLeft="20dp"
android:paddingTop="20dp"
android:text="Name : Vibha V\n\nJob Title : Student\nPhone Number : 9482263118\n"
android:textColor="#1E0202"
android:textSize="20dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:fontFamily="serif-monospace"
android:paddingLeft="20dp"
android:text="Address : #657, 22nd cross \n\t\t Kumaraswamy Layout ,\t Bengaluru\n"
android:textColor="#170101"
android:textSize="20dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:fontFamily="serif-monospace"
android:paddingLeft="20dp"
android:text="EMail : [email protected]\n Fax : 080 - 26663118\n\nWebsite :
www.github.com/vibha-v-657"
android:textColor="#220303"
android:textSize="20dp" /></LinearLayout>
Page 3
Mobile Application Development Lab (18CSMP68)
2) Develop an Android application using controls like Button, TextView, EditText for
designing a Calculator having basic functionality like Addition, Subtraction, Multiplication,
and Division.
activity_main.xml
Page 4
Mobile Application Development Lab (18CSMP68)
app:layout_constraintStart_toEndOf="@+id/button_six"
app:layout_constraintTop_toBottomOf="@+id/button_div" />
Page 5
Mobile Application Development Lab (18CSMP68)
app:layout_constraintStart_toEndOf="@+id/button_seven"
app:layout_constraintTop_toBottomOf="@+id/txt_result" />
MainActivity.java
package com.example.partaprogram2;
Page 6
Mobile Application Development Lab (18CSMP68)
import java.util.regex.Pattern;
btnOne=(Button)findViewById(R.id.button_one); btnOne.setOnClickListener(this);
btnTwo=(Button)findViewById(R.id.button_two); btnTwo.setOnClickListener(this);
btnThree=(Button)findViewById(R.id.button_three); btnThree.setOnClickListener(this);
btnFour=(Button)findViewById(R.id.button_four); btnFour.setOnClickListener(this);
btnFive=(Button)findViewById(R.id.button_five); btnFive.setOnClickListener(this);
btnSix=(Button)findViewById(R.id.button_six); btnSix.setOnClickListener(this);
btnSeven=(Button)findViewById(R.id.button_seven); btnSeven.setOnClickListener(this);
btnEight=(Button)findViewById(R.id.button_eight); btnEight.setOnClickListener(this);
btnNine=(Button)findViewById(R.id.button_nine); btnNine.setOnClickListener(this);
btnZero=(Button)findViewById(R.id.button_zero); btnZero.setOnClickListener(this);
btnAdd=(Button)findViewById(R.id.button_add); btnAdd.setOnClickListener(this);
btnSub=(Button)findViewById(R.id.button_sub); btnSub.setOnClickListener(this);
btnMul=(Button)findViewById(R.id.button_mul); btnMul.setOnClickListener(this);
btnDiv=(Button)findViewById(R.id.button_div); btnDiv.setOnClickListener(this);
btnClear=(Button)findViewById(R.id.button_clear); btnClear.setOnClickListener(this);
btnEqual=(Button)findViewById(R.id.button_equal); btnEqual.setOnClickListener(this);
btnDot=(Button)findViewById(R.id.button_dot); btnDot.setOnClickListener(this);
txtResult=(EditText)findViewById(R.id.txt_result); txtResult.setText("");
}
if(v.equals(btnEqual))
Page 7
Mobile Application Development Lab (18CSMP68)
{
try {
}
else if (data.contains("*")) {
String[] operands = data.split(Pattern.quote("*")); if(operands.length==2) {
double operand1 = Double.parseDouble(operands[0]); double operand2 =
Double.parseDouble(operands[1]);
double result = operand1 * operand2; txtResult.setText(String.valueOf(result));
}
else
{
Toast.makeText(getBaseContext(),"Invalid Input", Toast.LENGTH_LONG).show();
}
}
else if (data.contains("+")) {
String[] operands = data.split(Pattern.quote("+")); if(operands.length==2) {
double operand1 = Double.parseDouble(operands[0]); double operand2 =
Double.parseDouble(operands[1]); double result = operand1 + operand2;
txtResult.setText(String.valueOf(result));
}
else
{
Toast.makeText(getBaseContext(),"Invalid Input", Toast.LENGTH_LONG).show();
}
}
else if (data.contains("-")) { String[] operands = data.split("-"); if(operands.length==2) {
double operand1 = Double.parseDouble(operands[0]); double operand2 =
Double.parseDouble(operands[1]); double result = operand1 - operand2;
txtResult.setText(String.valueOf(result));
}
else
{
Page 8
Mobile Application Development Lab (18CSMP68)
Page 9
Mobile Application Development Lab (18CSMP68)
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.
Activity_main.xml
Page 10
Mobile Application Development Lab (18CSMP68)
Activity_login.xml
Page 11
Mobile Application Development Lab (18CSMP68)
MainActivity.java
package com.example.parta.program3;
import androidx.appcompat.app.AppCompatActivity; import android.content.Intent;
import android.os.Bundle;
import android.view.View; import android.widget.Button; import android.widget.EditText; import
android.widget.Toast;
import java.util.regex.Matcher; import java.util.regex.Pattern;
public class MainActivityextends AppCompatActivityimplements View.OnClickListener {
EditTexttxtUsername;
EditTexttxtPassword;
Button btnSignup;
String regularExpression="^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d)(?=.*[@$!])[A-Za- z\\d@$!]{8,}$";
@Override
Page 12
Mobile Application Development Lab (18CSMP68)
btnSignup=(Button)findViewById(R.id.btn_signup); btnSignup.setOnClickListener(this);
LoginActivity.java
package com.example.parta.program3;
Page 13
Mobile Application Development Lab (18CSMP68)
@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
btnLogin=(Button)findViewById(R.id.btn_login_signin); btnLogin.setOnClickListener(this);
if(user.equals(user1)&&pass.equals(pass1))
{
Toast.makeText(this,"Login Successful"
,Toast.LENGTH_LONG).show();
}
else
{
count++; if(count==3)
{
btnLogin.setEnabled(false); Toast.makeText(this, "Failed Login Attempts"
,Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(this,"Login Failed "+count
,Toast.LENGTH_LONG).show();
}
}
}
}
Page 14
Mobile Application Development Lab (18CSMP68)
Sample Output
Page 15
Mobile Application Development Lab (18CSMP68)
MainActivity.java
package com.example.wallpaper;
import androidx.appcompat.app.AppCompatActivity;
import android.app.WallpaperManager;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
Boolean running=false;
Button chnge;
int i = 1;
int[] images = new int[]{R.drawable.imga, R.drawable.imgb,
R.drawable.imgc, R.drawable.imgd,
R.drawable.imge, R.drawable.imgf};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@Override
public void onClick(View view) {
if (!running) {
new Timer().schedule(new MyTimer(), 0, 3000);
running = false;
}
Page 16
Mobile Application Development Lab (18CSMP68)
wallpaperManager.setBitmap(BitmapFactory.decodeResource(getResources(), images[i]));
} catch (Exception e) {
}
}
}
}
Activity_main.xml
Page 17
Mobile Application Development Lab (18CSMP68)
AndroidManifest.xml
Page 18
Mobile Application Development Lab (18CSMP68)
Page 19
Mobile Application Development Lab (18CSMP68)
5) Write a program to create an activity with two buttons START and STOP. On pressing of the
START button, the activity must start the counter by displaying the numbers from One and the
counter must keep on counting until the STOP button is pressed. Display the counter value in a
TextViewcontrol.
MainActivity.java
package com.example.counter;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
count=(TextView)findViewById(R.id.count);
start=(Button)findViewById(R.id.startbtn);
stop=(Button)findViewById(R.id.stopbtn);
start.setOnClickListener(this);
stop.setOnClickListener(this);
}
@Override
Page 20
Mobile Application Development Lab (18CSMP68)
new MyCounter().start();
}
else
running=false;
}
Handler handler= new Handler(){
public void handleMessage(Message counter)
{
count.setText(String.valueOf(counter.what));
}};
class MyCounter extends Thread
{
public void run()
{
while(running)
{
counter++;
handler.sendEmptyMessage(counter);
try{
Thread.sleep(100);
}
catch(Exception e){}
}
}
}
}
Activity_main.xml
Page 21
Mobile Application Development Lab (18CSMP68)
android:background="#EBB8F4"
tools:context=".MainActivity">
<TextView
android:id="@+id/heading"
android:layout_width="381dp"
android:layout_height="61dp"
android:fontFamily="casual"
android:gravity="center"
android:text="COUNTER APPLICATION"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textColor="#4E1B57"
android:textStyle="bold|italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.41"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.073" />
<Button
android:id="@+id/startbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="144dp"
android:background="#8D15A1"
android:fontFamily="casual"
android:text="START"
android:textColor="#FAF6F6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.507"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/heading" />
<EditText
android:id="@+id/count"
android:layout_width="79dp"
android:layout_height="80dp"
android:layout_marginStart="164dp"
android:layout_marginTop="152dp"
android:ems="10"
android:fontFamily="sans-serif-black"
android:gravity="center"
android:inputType="textPersonName"
Page 22
Mobile Application Development Lab (18CSMP68)
android:textColor="#2A0630"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/stopbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="172dp"
android:background="#781A88"
android:fontFamily="casual"
android:text="STOP"
android:textColor="#FAF6F6"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.535"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/startbtn"
app:layout_constraintVertical_bias="0.186" />
</androidx.constraintlayout.widget.ConstraintLayout>
Page 23
Mobile Application Development Lab (18CSMP68)
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.
activity_main.xml
Page 24
Mobile Application Development Lab (18CSMP68)
activity_view.xml
MainActivity.java
package com.example.parta_program6;
import androidx.appcompat.app.AppCompatActivity; import android.content.Intent;
import android.os.Bundle; import android.view.View; import android.widget.Button;
Page 25
Mobile Application Development Lab (18CSMP68)
@Override
public void onClick(View v) {
if(v.equals(btnParseJson))
{
Intent it=new Intent(this,ViewActivity.class); it.putExtra("mode",1);
startActivity(it);
}
else if(v.equals(btnParseXml))
{
Intent it=new Intent(this,ViewActivity.class); it.putExtra("mode",2);
startActivity(it);
}
}
}
ViewActivity.java
package com.example.parta_program6;
import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle;
import android.widget.TextView;
import java.io.InputStream;
if(mode==1) parseJson();
else parseXmlDocument();
Page 26
Mobile Application Development Lab (18CSMP68)
InputStream is = getAssets().open("input.xml");
DocumentBuilderFactorydbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilderdBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(is);
Page 27
Mobile Application Development Lab (18CSMP68)
lblJsonData.append("Temperature:"+jsonObject1.getInt("Temperature")+"\n");
lblJsonData.append("Humidity"+jsonObject1.getString("Humidity")+"\n");
}
catch (Exception e) {e.printStackTrace();}
}
}
Page 28
Mobile Application Development Lab (18CSMP68)
7) Develop a simple application withoneEditTextso that the user can write some text in it. Create
a button called “Convert Text to Speech” that converts the user input text into voice.
MainActivity.java
package com.example.lab7;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.util.Locale;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
input =(EditText)findViewById(R.id.input);
btn=(Button)findViewById(R.id.submit);
btn.setOnClickListener(this);
tts=new TextToSpeech(getBaseContext(), new TextToSpeech.OnInitListener() {
@Override
public void onInit(int i) {
if(i!=TextToSpeech.ERROR)
Toast.makeText(getBaseContext(), "Success", Toast.LENGTH_LONG).show();
}
});
tts.setLanguage(Locale.ENGLISH);
@Override
public void onClick(View view) {
Page 29
Mobile Application Development Lab (18CSMP68)
String text=input.getText().toString();
tts.speak(text,TextToSpeech.QUEUE_FLUSH,null);
}
}
Activity_main.xml
<TextView
android:id="@+id/textView"
android:layout_width="369dp"
android:layout_height="90dp"
android:fontFamily="cursive"
android:gravity="center"
android:text="Text to Speech Converter"
android:textColor="#C51FE1"
android:textSize="36sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.446"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.134" />
<EditText
android:id="@+id/input"
android:layout_width="383dp"
android:layout_height="168dp"
android:background="#F4EBEB"
android:ems="10"
android:gravity="center"
Page 30
Mobile Application Development Lab (18CSMP68)
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.571"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:layout_constraintVertical_bias="0.271" />
<Button
android:id="@+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#BB1BD6"
android:text="Convert Text to Speech"
android:textColor="#FAF6F6"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/input" />
</androidx.constraintlayout.widget.ConstraintLayout>
Page 31
Mobile Application Development Lab (18CSMP68)
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.
activity_main.xml
<Button android:id="@+id/btn_one"
Page 32
Mobile Application Development Lab (18CSMP68)
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="20dp" android:layout_marginTop="30dp" android:text="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_phonenumber" />
<Button android:id="@+id/btn_two"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="30dp" android:text="2"
app:layout_constraintEnd_toStartOf="@+id/btn_three"
app:layout_constraintStart_toEndOf="@+id/btn_one"
app:layout_constraintTop_toBottomOf="@+id/txt_phonenumber" />
<Button android:id="@+id/btn_three"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="30dp" android:layout_marginEnd="20dp" android:text="3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_phonenumber" />
<Button android:id="@+id/btn_four"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="20dp" android:layout_marginTop="30dp" android:text="4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_one" />
<Button android:id="@+id/btn_five"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="30dp" android:text="5"
app:layout_constraintEnd_toStartOf="@+id/btn_six"
app:layout_constraintStart_toEndOf="@+id/btn_four"
app:layout_constraintTop_toBottomOf="@+id/btn_two" />
<Button android:id="@+id/btn_six"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="30dp" android:layout_marginEnd="20dp" android:text="6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_three" />
<Button android:id="@+id/btn_seven"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="20dp" android:layout_marginTop="30dp" android:text="7"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_four" />
<Button android:id="@+id/btn_eight"
Page 33
Mobile Application Development Lab (18CSMP68)
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="8" app:layout_constraintEnd_toStartOf="@+id/btn_nine"
app:layout_constraintStart_toEndOf="@+id/btn_seven"
app:layout_constraintTop_toBottomOf="@+id/btn_five" />
<Button android:id="@+id/btn_nine"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="30dp" android:layout_marginEnd="20dp" android:text="9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_six" />
<Button android:id="@+id/btn_zero"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="30dp" android:text="0" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_eight" />
<Button android:id="@+id/btn_call"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="20dp" android:layout_marginTop="30dp" android:text="Call"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_zero" />
<Button android:id="@+id/btn_save"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="30dp" android:layout_marginEnd="20dp" android:text="Save"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_zero" />
<Button android:id="@+id/btn_start"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="20dp" android:layout_marginTop="30dp" android:text="*"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_seven" />
<Button android:id="@+id/btn_hash"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="30dp" android:layout_marginEnd="20dp" android:text="#"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_nine" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
Page 34
Mobile Application Development Lab (18CSMP68)
package com.example.part_a_program_8;
btnOne=(Button)findViewById(R.id.btn_one); btnOne.setOnClickListener(this);
btnTwo=(Button)findViewById(R.id.btn_two); btnTwo.setOnClickListener(this);
btnThree=(Button)findViewById(R.id.btn_three); btnThree.setOnClickListener(this);
btnFour=(Button)findViewById(R.id.btn_four); btnFour.setOnClickListener(this);
btnFive=(Button)findViewById(R.id.btn_five); btnFive.setOnClickListener(this);
btnSix=(Button)findViewById(R.id.btn_six); btnSix.setOnClickListener(this);
btnSeven=(Button)findViewById(R.id.btn_seven); btnSeven.setOnClickListener(this);
btnEight=(Button)findViewById(R.id.btn_eight); btnEight.setOnClickListener(this);
btnNine=(Button)findViewById(R.id.btn_nine); btnNine.setOnClickListener(this);
btnZero=(Button)findViewById(R.id.btn_zero); btnZero.setOnClickListener(this);
btnStar=(Button)findViewById(R.id.btn_start); btnStar.setOnClickListener(this);
btnHash=(Button)findViewById(R.id.btn_hash); btnHash.setOnClickListener(this);
btnCall=(Button)findViewById(R.id.btn_call); btnCall.setOnClickListener(this);
btnSave=(Button)findViewById(R.id.btn_save); btnSave.setOnClickListener(this);
btnDel=(Button)findViewById(R.id.btn_delete); btnDel.setOnClickListener(this);
txtPhonenumber=(EditText)findViewById(R.id.txt_phonenumber); txtPhonenumber.setText("");
}
Page 35
Mobile Application Development Lab (18CSMP68)
else if(v.equals(btnSave))
{
Intent contactIntent= new Intent
(ContactsContract.Intents.Insert.ACTION); contactIntent.setType
(ContactsContract.RawContacts.CONTENT_TYPE);
contactIntent.putExtra(ContactsContract.Intents.Insert.NAME,"Unknown");
contactIntent.putExtra(ContactsContract.Intents.Insert.PHONE, txtPhonenumber.getText().toString());
startActivity(contactIntent);
}
else if(v.equals(btnDel))
{
String data=txtPhonenumber.getText().toString(); if(data.length()>0)
{
txtPhonenumber.setText
(data.substring(0,data.length()-1));
}
else
{
txtPhonenumber.setText("");
}
}
btnCall.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
String data = txtPhonenumber.getText().toString(); Intent intent=new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:"+ data)); startActivity(intent);
}
}
);
}
Page 36
Mobile Application Development Lab (18CSMP68)
AndriodManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.part_a_program_8">
<uses-permission android:name="android.permission.CALL_PHONE"/>
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Sample Output
Page 37