Mad Manual Prints
Mad Manual Prints
Ans 2:
An activity is the single screen in android. It is like window or frame of Java. By
the help of activity, you can place all your UI components or widgets in a single screen.
The 7 lifecycle method of Activity describes how activity will behave at different states.
X. Exercise
Note: Faculty must ensure that every group of students use different input value.
(Use blank space for answers or attach more pages if needed)
1. Write a program to display HelloWorld.
2. Write a program to display student name and marks.
(Space for answers)
Ans 1:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Students_Information"
android:textColor="#161d6f"
android:textSize="30sp"
android:textStyle="bold" />
</TableRow>
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name: Heet ; Marks: 96"
android:textColor="#161d6f"
android:textSize="30sp"
android:textStyle="bold" />
</TableRow>
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name: Meet ; Marks: 97"
android:textColor="#161d6f"
Maharashtra State Board of Technical Education 21
Mobile Application Development (22617)
android:textSize="30sp"
android:textStyle="bold" />
</TableRow>
<TextView
android:id="@+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name: Pratik ; Marks: 99"
android:textColor="#161d6f"
android:textSize="30sp"
android:textStyle="bold" />
</TableRow>
<TextView
android:id="@+id/text4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name: Shaun ; Marks: 96"
android:textColor="#161d6f"
android:textSize="30sp"
android:textStyle="bold" />
</TableRow>
<TextView
android:id="@+id/text5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name: Naman ; Marks: 97"
android:textColor="#161d6f"
android:textSize="30sp"
android:textStyle="bold" />
</TableRow>
<TextView
android:id="@+id/text6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name: Hisbaan ; Marks: 92"
android:textColor="#161d6f"
android:textSize="30sp"
android:textStyle="bold" />
</TableRow>
</TableLayout>
Ans 1.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:layout_editor_absoluteX="199dp"
tools:layout_editor_absoluteY="362dp">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#03A9F4"
android:text="Name: Heet"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFC107"
android:text="Age:19"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold" />
Maharashtra State Board of Technical Education 27
Mobile Application Development (22617)
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#03A9F4"
android:text="Mobile_No:123456789"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
android:layout_height="match_parent"
android:background="#c7ffd8"
tools:context=".MainActivity"
tools:ignore="Deprecated">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="12dp"
android:layout_y="338dp"
android:text="Name: Heet"
android:textColor="#161d6f"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="135dp"
android:layout_y="338dp"
android:text="Age: 18"
android:textColor="#161d6f"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="213dp"
android:layout_y="338dp"
android:text="Phone_no: 123456789"
android:textColor="#161d6f"
android:textSize="18sp"
android:textStyle="bold" />
</AbsoluteLayout>
X. Exercise
Note: Faculty must ensure that every group of students use different input value.
(Use blank space for answers or attach more pages if needed)
1. Write a program to display 10 students basic information in a table
form using Table layout.
2. Write a program to display all the data types in object-oriented
programming using Frame layout.
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#31326f"
tools:layout_editor_absoluteX="125dp"
tools:layout_editor_absoluteY="245dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView1"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="center"
android:paddingTop="25dp"
android:paddingBottom="25dp"
android:text="Name"
android:textColor="#ffc93c"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView2"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_column="2"
Maharashtra State Board of Technical Education 35
Mobile Application Development (22617)
android:layout_gravity="center"
android:paddingTop="25dp"
android:paddingBottom="25dp"
android:text="AGE"
android:textColor="#ffc93c"
android:textSize="30sp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView3"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="center"
android:text="Heet"
android:textColor="#ffc93c"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView4"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_gravity="center"
android:text="19"
android:textColor="#ffc93c"
android:textSize="30sp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView5"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="center"
android:text="Shaun"
android:textColor="#ffc93c"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView6"
android:layout_width="170dp"
Maharashtra State Board of Technical Education 36
Mobile Application Development (22617)
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_gravity="center"
android:text="19"
android:textColor="#ffc93c"
android:textSize="30sp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView7"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="center"
android:text="Pratik"
android:textColor="#ffc93c"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView8"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_gravity="center"
android:text="18"
android:textColor="#ffc93c"
android:textSize="30sp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView9"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="center"
android:text="Gaurang"
android:textColor="#ffc93c"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView10"
android:layout_width="170dp"
Maharashtra State Board of Technical Education 37
Mobile Application Development (22617)
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_gravity="center"
android:text="19"
android:textColor="#ffc93c"
android:textSize="30sp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView11"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="center"
android:text="Meet"
android:textColor="#ffc93c"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView12"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_gravity="center"
android:text="19"
android:textColor="#ffc93c"
android:textSize="30sp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView13"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="center"
android:text="Naman"
android:textColor="#ffc93c"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView14"
android:layout_width="170dp"
Maharashtra State Board of Technical Education 38
Mobile Application Development (22617)
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_gravity="center"
android:text="18"
android:textColor="#ffc93c"
android:textSize="30sp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView15"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="center"
android:text="Divyesh"
android:textColor="#ffc93c"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView16"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_gravity="center"
android:text="19"
android:textColor="#ffc93c"
android:textSize="30sp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView17"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="center"
android:text="Harry"
android:textColor="#ffc93c"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView18"
android:layout_width="170dp"
Maharashtra State Board of Technical Education 39
Mobile Application Development (22617)
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_gravity="center"
android:text="19"
android:textColor="#ffc93c"
android:textSize="30sp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView19"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="center"
android:text="Ron"
android:textColor="#ffc93c"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView20"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_gravity="center"
android:text="18"
android:textColor="#ffc93c"
android:textSize="30sp"
android:textStyle="bold" />
</TableRow>
</TableLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#02475e"
tools:layout_editor_absoluteX="114dp"
Maharashtra State Board of Technical Education 41
Mobile Application Development (22617)
tools:layout_editor_absoluteY="242dp">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:text="LONG"
android:textColor="#fefecc"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:text="BOOLEAN"
android:textColor="#fefecc"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:text="INT"
android:textColor="#fefecc"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="CHAR"
android:textColor="#fefecc"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:text="FLOAT"
android:textColor="#fefecc"
android:textSize="30sp"
android:textStyle="bold" />
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
2. What is the name of the folder that contains the R.java file?
a. src
b. res
c. bin
d. gen
Ans 1 :
Non-visible is not defined as a process state.
Ans 2:
the name of the folder that contains the R.java file is Gen.
X. Exercise
Note: Faculty must ensure that every group of students use different input value.
(Use blank space for answers or attach more pages if needed)
1. Write a program to accept username and password from the end user using Text
View and Edit Text.
2. Write a program to accept and display personal information of the student.
<TextView
android:id="@+id/Username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="UserName"
android:layout_marginTop="150dp"
android:layout_marginLeft="40dp" />
<EditText
android:id="@+id/User_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:layout_toRightOf="@+id/Username"
<TextView
android:id="@+id/Password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"
android:layout_marginTop="40dp"
android:layout_below="@+id/Username"
android:layout_marginLeft="40dp"
/>
<EditText
android:id="@+id/Pass_word"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginTop="190dp"
android:layout_toRightOf="@+id/Password"
android:ems="10"
android:inputType="textPassword" />
<Button
android:id="@+id/Submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Submit"
android:layout_marginTop="200dp"
android:layout_below="@+id/Pass_word"
/>
</RelativeLayout>
<TextView
android:id="@+id/Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:text="Name" />
<EditText
android:id="@+id/editText_Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="60dp"
android:layout_marginRight="@+id/Name"
android:ems="10" />
<EditText
android:id="@+id/editText_age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/Name"
android:layout_margin="60dp"
android:layout_marginRight="@+id/Age"
android:ems="10" />
<Button
android:id="@+id/Submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="260dp"
android:text="Submit" />
<TextView
android:id="@+id/Student_Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/Submit"
android:visibility="invisible" />
<TextView
android:id="@+id/Student_age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/Student_Name"
android:visibility="invisible" />
</RelativeLayout>
}
public void go()
{
Name=findViewById(R.id.editText_Name);
Age=findViewById(R.id.editText_age);
name=Name.getText().toString().trim();
age=Age.getText().toString().trim();
Display_Name=findViewById(R.id.Student_Name);
Display_Age=findViewById(R.id.Student_age);
Display_Name.setVisibility(View.VISIBLE);
Display_Name.setText("Name:"+name);
Display_Age.setVisibility(View.VISIBLE);
Display_Age.setText("Age:"+age);
}
}
X. Exercise
Note: Faculty must ensure that every group of students use different
input value.
(Use blank space for answers or attach more pages if needed)
1. Write a program to create a toggle button to display ON / OFF Bluetooth on the
display screen.
2. Write a program to create a simple calculator.
Output
X. Exercise
Note: Faculty must ensure that every group of students use different
input value.
(Use blank space for answers or attach more pages if needed)
1. Write a program to create a login form for a social networking site.
2. Write a program to create a login form for student registration system
super.onCreate(savedInstanceStat xmlns:app="http://schemas.andro
e); id.com/apk/res-auto"
setContentView(R.layout.activity_ xmlns:tools="http://schemas.andr
main); oid.com/tools"
username=findViewById(R.id.Use android:layout_width="match_pa
rname_ET); rent"
login=findViewById(R.id.Login); android:layout_height="match_p
arent"
login.setOnClickListener(new tools:context=".MainActivity">
View.OnClickListener()
{ <TextView
@Override android:id="@+id/Name"
public void onClick(View
v) { android:layout_width="wrap_con
tent"
Username=username.getText().toS
tring(); android:layout_height="wrap_co
ntent"
Toast.makeText(MainActivity.this android:text="Name"
,"Welcome
"+Username,Toast.LENGTH_SH android:layout_marginTop="40d
ORT).show(); p"
Intent intent=new
Intent(MainActivity.this,Empty_A android:layout_centerHorizontal=
ctivity.class); "true"
// android:textSize="20dp"
intent.putExtra("username",User />
name); <EditText
startActivity(intent);
android:id="@+id/Name_ET"
}
Maharashtra State Board of Technical Education 70
Mobile Application Development (22617)
android:layout_width="match_pa
rent" android:inputType="textPersonN
ame"
android:layout_height="wrap_co
ntent" android:layout_marginTop="20d
android:ems="10" p"
android:inputType="textPersonN android:layout_below="@+id/Age
ame" "
/>
android:layout_below="@+id/Na <TextView
me" android:id="@+id/Branch"
android:layout_marginTop="20d android:layout_width="wrap_con
p" tent"
/>
<TextView android:layout_height="wrap_co
android:id="@+id/Age" ntent"
android:text="Branch"
android:layout_width="wrap_con
tent" android:layout_marginTop="40d
p"
android:layout_height="wrap_co
ntent" android:layout_centerHorizontal=
android:text="Age" "true"
android:layout_marginTop="40d android:layout_below="@+id/Age
p" _ET"
android:textSize="20dp"
android:layout_centerHorizontal=
"true" />
<EditText
android:layout_below="@+id/Na
me_ET" android:id="@+id/Branch_ET"
android:textSize="20dp"
/> android:layout_width="match_pa
<EditText rent"
android:id="@+id/Age_ET"
android:layout_height="wrap_co
android:layout_width="match_pa ntent"
rent" android:ems="10"
android:layout_height="wrap_co android:inputType="textPersonN
ntent" ame"
android:ems="10"
Maharashtra State Board of Technical Education 71
Mobile Application Development (22617)
android:layout_marginTop="20d
p" android:layout_below="@+id/Se
mester"
android:layout_below="@+id/Bra />
nch" <Button
/> android:id="@+id/Login"
<TextView
android:id="@+id/Semester" android:layout_width="wrap_con
tent"
android:layout_width="wrap_con
tent" android:layout_height="wrap_co
ntent"
android:layout_height="wrap_co android:text="Login"
ntent"
android:text="Semester" android:layout_below="@+id/Se
mester_ET"
android:layout_marginTop="40d
p" android:layout_marginTop="40d
p"
android:layout_centerHorizontal=
"true" android:layout_centerHorizontal=
"true"
android:layout_below="@+id/Bra />
nch_ET"
android:textSize="20dp" <TextView
/> android:id="@+id/Login"
<EditText
android:layout_width="wrap_con
android:id="@+id/Semester_ET" tent"
android:layout_width="match_pa android:layout_height="wrap_co
rent" ntent"
android:text="Student Login"
android:layout_height="wrap_co android:textSize="40dp"
ntent"
android:ems="10" android:layout_centerHorizontal=
"true"
android:inputType="textPersonN
ame" android:textColor="@color/teal_2
00"
android:layout_marginTop="20d />
p" </RelativeLayout>
Output:
Ans 2.
XML file
<?xml version="1.0" android:layout_width="match_pa
encoding="utf-8"?> rent"
<RelativeLayout
xmlns:android="http://schemas.a android:layout_height="match_p
ndroid.com/apk/res/android" arent"
tools:context=".MainActivity">
xmlns:app="http://schemas.andro
id.com/apk/res-auto" <TextView
android:id="@+id/Name"
xmlns:tools="http://schemas.andr
oid.com/tools" android:layout_width="wrap_con
Maharashtra State Board of Technical Education 73
Mobile Application Development (22617)
tent"
android:layout_centerHorizontal=
android:layout_height="wrap_co "true"
ntent"
android:text="Name" android:layout_below="@+id/Na
me_ET"
android:layout_marginTop="40d android:textSize="20dp"
p" />
<EditText
android:layout_centerHorizontal= android:id="@+id/Age_ET"
"true"
android:textSize="20dp" android:layout_width="match_pa
/> rent"
<EditText
android:layout_height="wrap_co
android:id="@+id/Name_ET" ntent"
android:ems="10"
android:layout_width="match_pa
rent" android:inputType="textPersonN
ame"
android:layout_height="wrap_co
ntent" android:layout_marginTop="20d
android:ems="10" p"
android:inputType="textPersonN android:layout_below="@+id/Age
ame" "
/>
android:layout_below="@+id/Na <TextView
me" android:id="@+id/Branch"
android:layout_marginTop="20d android:layout_width="wrap_con
p" tent"
/>
<TextView android:layout_height="wrap_co
android:id="@+id/Age" ntent"
android:text="Branch"
android:layout_width="wrap_con
tent" android:layout_marginTop="40d
p"
android:layout_height="wrap_co
ntent" android:layout_centerHorizontal=
android:text="Age" "true"
android:layout_marginTop="40d android:layout_below="@+id/Age
p" _ET"
Maharashtra State Board of Technical Education 74
Mobile Application Development (22617)
android:textSize="20dp" android:id="@+id/Semester_ET"
/> android:layout_width="match_pa
<EditText rent"
android:id="@+id/Branch_ET" android:layout_height="wrap_co
ntent"
android:layout_width="match_pa android:ems="10"
rent"
android:inputType="textPersonN
android:layout_height="wrap_co ame"
ntent"
android:ems="10" android:layout_marginTop="20d
p"
android:inputType="textPersonN
ame" android:layout_below="@+id/Se
mester"
android:layout_marginTop="20d />
p" <Button
android:id="@+id/Login"
android:layout_below="@+id/Bra
nch" android:layout_width="wrap_con
/> tent"
<TextView
android:id="@+id/Semester" android:layout_height="wrap_co
ntent"
android:layout_width="wrap_con android:text="Login"
tent"
android:layout_below="@+id/Se
android:layout_height="wrap_co mester_ET"
ntent"
android:text="Semester" android:layout_marginTop="40d
p"
android:layout_marginTop="40d
p" android:layout_centerHorizontal=
"true"
android:layout_centerHorizontal= />
"true"
<TextView
android:layout_below="@+id/Bra android:id="@+id/Login"
nch_ET"
android:textSize="20dp" android:layout_width="wrap_con
/> tent"
<EditText
android:layout_height="wrap_co
Maharashtra State Board of Technical Education 75
Mobile Application Development (22617)
ntent" e);
android:text="Student Login"
android:textSize="40dp" setContentView(R.layout.activity_
main);
android:layout_centerHorizontal=
"true" name_et=findViewById(R.id.Nam
e_ET);
android:textColor="@color/teal_2
00" age_et=findViewById(R.id.Age_E
/> T);
</RelativeLayout>
branch_et=findViewById(R.id.Br
Java File: anch_ET);
package com.example.exp10_2;
sem_et=findViewById(R.id.Semes
ter_ET);
import login
androidx.appcompat.app.AppCo =findViewById(R.id.Login);
mpatActivity;
import android.content.Intent; login.setOnClickListener(new
import android.os.Bundle; View.OnClickListener()
import android.view.View; {
import android.widget.Button; @Override
import android.widget.EditText; public void onClick(View
import android.widget.Toast; v) {
import
android.widget.ToggleButton; Username=name_et.getText().toSt
ring();
import android.os.Bundle;
Age=age_et.getText().toString();
public class MainActivity extends
AppCompatActivity { Branch=branch_et.getText().toStr
ing();
EditText
name_et,age_et,branch_et,sem_et Semester=sem_et.getText().toStrin
; g();
String
Username,Age,Branch,Semester; Toast.makeText(MainActivity.this
Button login; ,"Welcome "+Username
,Toast.LENGTH_SHORT).show()
@Override ;
protected void onCreate(Bundle
savedInstanceState) { Toast.makeText(MainActivity.this
,"Age "+Age
super.onCreate(savedInstanceStat ,Toast.LENGTH_SHORT).show()
Maharashtra State Board of Technical Education 76
Mobile Application Development (22617)
; Intent(MainActivity.this,Empty_A
ctivity.class);
Toast.makeText(MainActivity.this //
,"Branch "+Branch intent.putExtra("username",User
,Toast.LENGTH_SHORT).show() name);
; startActivity(intent);
Toast.makeText(MainActivity.this }
,"Semester "+Semester });
,Toast.LENGTH_SHORT).show()
; }
}
Intent intent=new
Output:
Ans 1.
XML Code:
android:id="@+id/radioButt
<?xml version="1.0" on1"
encoding="utf-8"?>
<RelativeLayout android:layout_width="wrap
xmlns:android="http://schem _content"
as.android.com/apk/res/andro
id" android:layout_height="wrap
_content"
xmlns:app="http://schemas.a android:text="Radio
ndroid.com/apk/res-auto" Button 1"
xmlns:tools="http://schemas. android:layout_marginTop="
android.com/tools" 80dp"
android:textSize="40dp"
android:layout_width="matc />
h_parent" <RadioButton
android:layout_height="matc android:id="@+id/radioButt
h_parent" on2"
tools:context=".MainActivity android:layout_width="wrap
"> _content"
<TextView android:layout_height="wrap
_content"
android:id="@+id/textv" android:text="Radio
Button 2"
android:layout_width="wrap
_content" android:layout_marginTop="
40dp"
android:layout_height="wrap
_content" android:layout_below="@+id
android:text="Single /radioButton1"
Radio Buttons" android:textSize="40dp"
/>
android:textColor="#000000
" <RadioGroup
android:visibility="visible" android:layout_below="@+id
/radioButton2"
android:layout_centerHorizo
ntal="true" android:layout_width="matc
android:textSize="20dp" h_parent"
android:layout_marginTop=" android:layout_height="200d
20dp" p"
/>
<RadioButton android:layout_marginTop="
Maharashtra State Board of Technical Education 82
Mobile Application Development (22617)
50dp" android:checked="true"
android:id="@+id/radioGrou android:textSize="40dp"
p"> />
</RadioGroup>
<TextView <Button
android:id="@+id/textvr" android:id="@+id/Select"
android:layout_width="wrap android:layout_width="wrap
_content" _content"
android:layout_height="wrap android:layout_height="wrap
_content" _content"
android:text="Radio android:text="Select"
button inside RadioGroup"
android:layout_centerHorizo
android:textSize="20dp" ntal="true"
android:textColor="#000000 android:layout_below="@+id
" /radioGroup"
/>
android:visibility="visible" </RelativeLayout>
Java Code:
android:layout_marginTop="
25dp" package com.example.exp12;
/>
<RadioButton import
androidx.appcompat.app.App
android:id="@+id/male" CompatActivity;
setContentView(R.layout.acti radgender=findViewById(rad
vity_main); ioID);
radSelect=findViewById(R.id gender=radgender.getText().t
.radioGroup); oString().trim();
if(rad1.isChecked())
rad1=findViewById(R.id.radi {
oButton1); Toast.makeText(this,
"Radio button 1 is selected",
rad2=findViewById(R.id.radi Toast.LENGTH_SHORT).sho
oButton2); w();
}
select=findViewById(R.id.Sel if(rad2.isChecked())
ect); {
Toast.makeText(this,
select.setOnClickListener( "Radio button 2 is selected",
new View.OnClickListener() { Toast.LENGTH_SHORT).sho
public w();
void onClick(View v) { }
Toast.makeText(this,
select(); "Gender :" + gender,
} Toast.LENGTH_SHORT).sho
} w();
); }
} }
public void select()
</GridView>
ActivityMain.java
import android.app.Activity;
import android.os.Bundle;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;
import android.view.View;
import android.widget.AdapterView.OnItemClickListener;
public class MainActivity extends Activity {
GridView grid;
static final String[] letters = new String[] {
"A", "B", "C", "D", "E",
"F", "G", "H", "I", "J",
"K", "L", "M", "N", "O",
"P", "Q", "R", "S", "T",
"U", "V", "W", "X", "Y", "Z"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
grid = (GridView) findViewById(R.id.gridView);
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, letters);
grid.setAdapter(adapter);
grid.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id)
{
Mah arashtra State Board of Technical Education 96
Mobile Application Development (22617)
Toast.makeText(getApplicationContext(),
((TextView) v).getText(), Toast.LENGTH_SHORT).show();
}
});
}
}
3. Run the application
X. Exercise
(Use blank space provide for answers or attached more pages if needed)
1. Write a program to show the following output. Use appropriate view for the same.
Ans
XML code
import
<?xml version="1.0" encoding="utf-8"?> androidx.appcompat.app.AppCompatActiv
<RelativeLayout ity;
xmlns:android="http://schemas.android.co
m/apk/res/android" import android.os.Bundle;
xmlns:app="http://schemas.android.com
/apk/res-auto" public class MainActivity extends
xmlns:tools="http://schemas.android.co AppCompatActivity {
m/tools"
android:layout_width="match_parent" @Override
android:layout_height="match_parent" protected void onCreate(Bundle
tools:context=".MainActivity"> savedInstanceState) {
super.onCreate(savedInstanceState);
<ListView setContentView(R.layout.activity_ma
android:layout_width="match_parent in);
" }
android:layout_height="match_parent }
"
android:entries="@array/Language_li
st"
/>
</RelativeLayout>
strings.xml
<resources>
<string
name="app_name">Exp14_1</string>
<array name="Language_list">
<item>Android</item>
<item>Java</item>
<item>PHP</item>
<item>Hadoop</item>
<item>Sap</item>
<item>Phython</item>
<item>Ajax</item>
<item>C++</item>
<item>Puby</item>
<item>Rails</item>
</array>
</resources>
Java Code
package com.example.exp14_1;
Maharashtra State Board of Technical Education 98
Mobile Application Development (22617)
Output:
Ans 2:
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="347dp" />
<Button
android:id="@+id/button1"
android:layout_width="200dp"
android:layout_height="58dp"
android:gravity="center"
android:onClick="mess"
android:text="First Image "
android:textSize="20sp" />
<Button
android:id="@+id/button2"
android:layout_width="218dp"
android:layout_height="63dp"
android:onClick="mess"
android:text="Second Image"
android:textSize="20sp" />
</LinearLayout>
ActivityMain.java
package com.example.exp14_2;
Maharashtra State Board of Technical Education 100
Mobile Application Development (22617)
import
android.os.Bundle;
import
android.view.View;
import
android.widget.ImageView;
import
android.widget.TextView;
import android.app.Activity;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void mess(View v)
{
//initialize image view object
ImageView im=(ImageView)findViewById(R.id.imageView1);
//get clicked button id from view object
switch(v.getId())
{
case R.id.button1:
//if button1 is clicked than set image1
im.setImageResource(R.drawable.myi
mage); break;
case R.id.button2:
//if button2 is clicked than set image2
im.setImageResource(R.drawable.myi
mage2); break;
}
}
}
Ans 3
<?xml version="1.0" encoding="utf-8"?>
<GridView 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:id="@+id/activity_grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="50dp"
Maharashtra State Board of Technical Education 102
android:listSelector="@color/white"
Mobile Application Development (22617)
android:numColumns="3"
android:padding="20dp"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp"
tools:context=".MainActivity" />
MainActivity.java
package com.example.exp14_3;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.GridView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView gridview = (GridView) findViewById(R.id.activity_grid);
gridview.setAdapter(new ButtonAdapter(this));
}
}
ButtonAdapter.java
package com.example.exp14_3;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Toast;
public class ButtonAdapter extends BaseAdapter
{
private Context mContext;
private int btn_id;
private int total_btns = 15;
Maharashtra State Board of Technical Education 103
Mobile Application Development (22617)
4) Ans:
XML File:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Exp_14_3">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="Scroll down"
android:textSize="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView2"
android:layout_centerHorizontal="true"
android:layout_marginTop="1000dp"
android:text="You have scrolled too far..."
android:textSize="20dp"/>
</RelativeLayout>
</ScrollView>
Java File:
package com.example.exp14_4;
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);
}
}
Maharashtra State Board of Technical Education 105
X. Exercise
(Use blank space provide for answers or attached more pages if needed)
1. Write a program to create a HelloWorld Activity using all lifecycles methods to
display messages using Log.d.
Ans1:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/andro
id"
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">
</androidx.constraintlayout.widget.ConstraintLayout>
Java code
package com.example.exp_17_1;
import
androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.os.Bundle;
AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("lifecycle","onCreate invoked by meena
talele");
}
@Override
protected void onStart() {
super.onStart();
Log.i("lifecycle","onStart
invoked");
}
@Override
protected void onResume(){
super.onResume();
Log.v("lifecycle","onResume
invoked");
}
@Override
protected void onPause(){
super.onPause();
Log.d("lifecycle","onPause
invoked");
}
@Override
protected void onStop(){
super.onStop();
Log.d("lifecycle","onStop
invoked");
}
@Override
protected void onRestart(){
super.onRestart();
Log.d("lifecycle","onRestart
invoked");
}
@Override
protected void onDestroy(){
super.onDestroy();
Log.d("lifecycle","onDestroy
invoked");
}
//DONE BY Heet Zatakia
Output:
btnNavigate=findViewById(R.id.btnNavigate);
btnNavigate.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
editText=findViewById(R.id.edittext);
text=editText.getText().toString().trim();
if(text.equals("www.youtube.com"))
{
go();
}
}
});
}
public void go()
{
Uri uri=Uri.parse("https://www.youtube.com"); Intent
intent=new Intent(Intent.ACTION_VIEW,uri);
startActivity(intent);
}
}
<EditText android:id="@+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
Maharashtra State Board of Technical Education 11
Mobile Application Development (22617)
android:hint="Enter URL"
/>
<Button
android:id="@+id/btnNavigate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Navigate"
android:layout_below="@+id/edittext"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
/>
</RelativeLayout>
Output:
Ans 2:
<Button
android:id="@+id/btnOpenDialer" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Open Dialer"
android:layout_centerInParent="true"
/>
</RelativeLayout>
Java
package com.example.exp18_2;
@Override
Intent((Intent.ACTION_DIAL));
startActivity(intent);
}
);
}
}
Ans 3) activity_main.xml
<xml version=”1.0” encoding=”utf-8”?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:app=”http://schemas.android.com/apk/res-auto”
xmlns:tools=”http://schemas.android.com/tools”
android:id=”@+id/relativeLayout”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
tools:context=”.MainActivity”>
<EditText
android:id=”@+id/editText”
android:layout_width=”315dp”
android:layout_height=”53dp”
android:layout_centerHorizontal=”true”
android:layout_centerVertical=”true”
android:fontFamily=”@font/poppins_medium”
android:hint=”Enter a number”
android:inputType=”number”
android:textSize=”20sp”
app:layout_constraintBottom_toBottomOf=”parent”
app:layout_constraintLeft_toLeftOf=”parent”
app:layout_constraintRight_toRightOf=”parent”
app:layout_constraintTop_toTopOf=”parent”
app:layout_constraintVertical_bias=”0.371”/>
MainActivity.java
package com.example.exp18_2;
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;
public class MainActivity extends AppCompatActivity
{EditText editText;
Button btnFact;
int fact = 1;
int num=0;
@Override
protected void onCreate(Bundle savedInstanceState)
{super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = findViewById(R.id.editText);
btnFact = findViewById(R.id.btnFact);
btnFact.setOnClickListener(new View.OnClickListener()
{@Override
public void onClick(View v)
{go();
}
});
}
public void go(){
num = Integer.parseInt(editText.getText().toString().trim());
for(int i = 1; i <= num; i++){
fact = fact * i;
}
navigate();
}
public void navigate(){
Intent intent = new Intent(MainActivity.this,EmptyActivity.class);
intent.putExtra(“Fact”,fact);
intent.putExtra(“Num”,num);
startActivity(intent);
}
}
EmptyActivity.java
package com.example.exp18_2;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class EmptyActivity extends AppCompatActivity
{TextView textView1,textView2;
int num,fact;
@Override
protected void onCreate(Bundle savedInstanceState)
{super.onCreate(savedInstanceState);
setContentView(R.layout.activity_empty);
Intent intent = getIntent();
num = intent.getIntExtra(“Num”,0);
fact = intent.getIntExtra(“Fact”,0);
textView1 = findViewById(R.id.textview1);
textView2 = findViewById(R.id.textview2);
textView1.setText(“Number = “+ num);
textView2.setText(“Factorial = “+ fact);
}
Maharashtra State Board of Technical Education 136
Mobile Application Development (22617)
}
ActivityMain.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayoutxmlns:android="http://schemas.android.com/a
pk/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">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="97dp"
android:layout_marginTop="341dp"
android:text="Broadcasting button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
package com.example.exp21;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
@Override
protected void onDestroy()
{ super.onDestroy();
MainActivity.this.
unregisterReceiver(myReceiver);
}
}
MyReceiver.java
package com.example.exp21;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
@Override
public void onReceive(Context context, Intent intent)
{String intentAction = intent.getAction();
if(intentAction != null){
String toastMessage = "unknown intent action";
Maharashtra State Board of Technical Education 142
Mobile Application Development (22617)
switch(intentAction){
case Intent.ACTION_AIRPLANE_MODE_CHANGED:
boolean status = intent.getBooleanExtra("state",true);
if(status){
toastMessage = "Airoplane Mode turned on";
}else {
toastMessage = "Airoplane Mode turned off";
}
break;
}
Toast.makeText(context,toastMessage,Toast.LENGTH_SHORT).show();
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.broadcast_messages">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Exp21">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</application>
</manifest>
iii. Avoid using deprecated methods or sensor types: Several methods and constants
have been deprecated. In particular, the TYPE_ORIENTATION sensor type has been
deprecated.
iv. Verify sensors before you use them: Always verify that a sensor exists on a device
before you attempt to acquire data from it. Don't assume that a sensor exists
simply because it's a frequently-used sensor.
v. Choose sensor delays carefully: Sensors can provide data at very high rates.
Allowing the system to send extra data that you don't need wastes systemresources
and uses battery power.
You can get the instance of SensorManager by calling the method getSystemService() and
passing the SENSOR_SERVICE constant in it.
SensorManager sm = (SensorManager)getSystemService(SENSOR_SERVICE);
Exercise
Note: Faculty must ensure that every group of students use different input value.
(Use blank space for answers or attach more pages if needed)
3. Write a program to changes the background color when device is shuffled.
4. Write a program to display the list of sensors supported by the mobile device.
Ans 4) actvity_main.xml
MainActivity.java
package com.example.exp22_1;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Build;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.List;
public class MainActivity extends AppCompatActivity
{SensorManager smm;
List<Sensor> sensor;
ListView lv;
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
protected void onCreate(Bundle savedInstanceState)
{super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
smm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
lv = (ListView) findViewById (R.id.listView1);
sensor = smm.getSensorList(Sensor.TYPE_ALL);
lv.setAdapter(new ArrayAdapter<Sensor>(this,android.R.layout.simple_list_item_1,
sensor));
}
}
Ans 1) activity_main.xml
<LinearLayout 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”
android:orientation=”vertical”>
<ImageView
android:id=”@+id/imageView”
android:layout_width=”fill_parent”
android:layout_height=”403dp”
android:layout_centerHorizontal=”true” />
<Button
android:id=”@+id/button”
android:layout_width=”match_parent”
android:layout_height=”73dp”
android:fontFamily=”@font/poppins_medium”
android:text=”Click here to capture image using camera”/>
</LinearLayout>
MainActivity.java
package com.example.exp23;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.Manifest;
Ans 2) activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:context=".MainActivity"
android:orientation="vertical">
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="Capture Video"
android:onClick="captureVideo"
android:layout_gravity="center_horizontal"
android:layout_marginTop="150dp"
/>
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="Play Video"
android:onClick="playVideo"
android:layout_gravity="center_horizontal"
android:layout_marginTop="25dp"
/>
</LinearLayout>
MainActivty.java
package com.example.exp23_2;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
public class MainActivity extends AppCompatActivity
{private static int VIDEO_REQUEST = 101;
private Uri videoUri = null;
@Override
protected void onCreate(Bundle savedInstanceState)
{super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void captureVideo(View view) {
Intent videoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if(videoIntent.resolveActivity(getPackageManager())!=null)
{ startActivityForResult(videoIntent,VIDEO_REQUEST);
}
}
public void playVideo(View view) {
Intent playIntent = new Intent(this,VideoPlayActivity.class);
playIntent.putExtra("videoUri", videoUri.toString());
startActivity(playIntent);
Maharashtra State Board of Technical Education 158
Mobile Application Development (22617)
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{super.onActivityResult(requestCode, resultCode, data);
if (requestCode == VIDEO_REQUEST && resultCode == RESULT_OK)
{videoUri = data.getData();
}
}
}
activity_play_video.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=".VideoPlayActivity">
<VideoView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="35dp"
android:id="@+id/videoView"
/>
</RelativeLayout>
VideoPlayActivity.java
package com.example.exp23_2;
import androidx.appcompat.app.AppCompatActivity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.VideoView;
public class VideoPlayActivity extends AppCompatActivity
{private VideoView mVideoView;
@Override
protected void onCreate(Bundle savedInstanceState)
{super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_play);
mVideoView = findViewById(R.id.videoView);
Uri videoUri = Uri.parse(getIntent().getExtras().getString("videoUri"));
mVideoView.setVideoURI(videoUri);
mVideoView.start();
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.exp23_2">
<uses-feature
android:name="android.hardware.camera2"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
Maharashtra State Board of Technical Education 159
Mobile Application Development (22617)
android:supportsRtl="true"
android:theme="@style/Theme.Exp23_2">
<activity android:name=".VideoPlayActivity"></activity>
<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>
Activity_main.xml
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="56dp"
android:layout_marginTop="72dp"
android:text="Bluetooth_example"
android:textSize="35dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="54dp"
android:text="Turn On"
app:layout_constraintEnd_toStartOf="@+id/button2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
android:clickable="true"
android:onClick="on"
/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="54dp"
android:text="ListDevices"
app:layout_constraintEnd_toStartOf="@+id/button3"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/button"
app:layout_constraintTop_toBottomOf="@+id/textView"
android:onClick="list"/>
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Maharashtra State Board of Technical Education 164
Mobile Application Development (22617)
android:layout_marginTop="54dp"
android:text="Turn Off"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/button2"
app:layout_constraintTop_toBottomOf="@+id/textView"
android:onClick="off"/>
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="136dp"
android:layout_marginTop="40dp"
android:text="Get Visisble"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button2"
android:onClick="visible"/>
<ListView
android:id="@+id/listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="84dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button4" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="11dp"
android:layout_marginTop="27dp"
android:text="Paired Device"
android:textColor="#ff34ff06"
android:textSize="25dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button4" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.exp24;
import androidx.appcompat.app.AppCompatActivity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Set;
Maharashtra State Board of Technical Education 165
Mobile Application Development (22617)
public class MainActivity extends AppCompatActivity
{Button b1,b2,b3,b4;
private BluetoothAdapter BA;
private Set<BluetoothDevice>pairedDevices;
ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState)
{super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = findViewById(R.id.button);
b2 = findViewById(R.id.button2);
b3 = findViewById(R.id.button3);
b4 = findViewById(R.id.button4);
BA = BluetoothAdapter.getDefaultAdapter();
lv = findViewById(R.id.listView);
}
public void on(View
v){if(!BA.isEnabled()
){
Intent turnOn = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(turnOn,0);
Toast.makeText(getApplicationContext(),"Turned On", Toast.LENGTH_LONG).show();
}else {
Toast.makeText(getApplicationContext(),"Already On", Toast.LENGTH_LONG).show();
}
}
public void off(View
v){BA.disable();
Toast.makeText(getApplicationContext(),"Turned Off", Toast.LENGTH_LONG).show();
}
public void visible(View v){
Intent getVisible = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
startActivityForResult(getVisible,0);
}
public void list(View
v){ pairedDevices =
BA.getBondedDevices();ArrayList list =
new ArrayList();
for(BluetoothDevicebt : pairedDevices) list.add(bt.getName());
Toast.makeText(getApplicationContext(),"Show Paired Devices",
Toast.LENGTH_LONG).show();
final ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1,list);
lv.setAdapter(adapter);
}
}
Android_Manifest.xml
1 Gaurang Jadhav
2 Shweta Gupta
3 Heet Zatakia
android:id="@+id/relativeLayout">
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="Bluetooth Example"
android:textSize="35dp"
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_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="28dp"
android:layout_toStartOf="@+id/imageView"
android:layout_toLeftOf="@+id/imageView"
android:clickable="true"
android:onClick="on"
android:text="Turn On"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textview" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textview"
android:layout_alignBottom="@+id/button"
android:layout_centerHorizontal="true"
android:layout_marginStart="144dp"
android:layout_marginLeft="144dp"
android:layout_marginTop="24dp"
android:onClick="visible"
android:text="Get visible"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button3" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="136dp"
android:layout_marginLeft="136dp"
android:layout_marginTop="28dp"
android:onClick="list"
android:text="List devices"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textview" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="28dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:onClick="off"
android:text="turn off"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textview" />
<ListView
android:id="@+id/listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView2"
android:layout_alignStart="@+id/button"
android:layout_alignLeft="@+id/button"
android:layout_alignParentBottom="true"
app:layout_constraintStart_toStartOf="@+id/button"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button4"
android:layout_alignStart="@+id/listView"
android:layout_alignLeft="@+id/listView"
android:layout_marginStart="24dp"
android:layout_marginLeft="24dp"
android:layout_marginTop="24dp"
android:text="Paired devices:"
android:textColor="#ff34ff06"
android:textSize="25dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button2" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.exp24;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Set;
public class MainActivity extends Activity {
Button b1,b2,b3,b4;
private BluetoothAdapter BA;
private Set<BluetoothDevice>pairedDevices;
ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button) findViewById(R.id.button);
b2=(Button)findViewById(R.id.button2);
b3=(Button)findViewById(R.id.button3);
b4=(Button)findViewById(R.id.button4);
BA = BluetoothAdapter.getDefaultAdapter();
lv = (ListView)findViewById(R.id.listView);
}
public void on(View v){
if (!BA.isEnabled()) {
Intent turnOn = new
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(turnOn, 0);
Toast.makeText(getApplicationContext(), "Turned
on",Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Already on",
Toast.LENGTH_LONG).show();
}
}
public void off(View v){
BA.disable();
Toast.makeText(getApplicationContext(), "Turned off"
,Toast.LENGTH_LONG).show();
}
public void visible(View v){
Intent getVisible = new
Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
startActivityForResult(getVisible, 0);
}
public void list(View v){
pairedDevices = BA.getBondedDevices();
ArrayList list = new ArrayList();
for(BluetoothDevice bt : pairedDevices) list.add(bt.getName());
Toast.makeText(getApplicationContext(), "Showing Paired
Devices",Toast.LENGTH_SHORT).show();
final ArrayAdapter adapter = new
ArrayAdapter(this,android.R.layout.simple_list_item_1, list);
lv.setAdapter(adapter);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.exp24">
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Exp24">
<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>
X. Exercise
Note: Faculty must ensure that every group of students use different input values.
(Use blank space for answers or attach more pages if needed)
1. Write a program to insert data in SQLite database using AsyncTask
Ans1) 1. activity_main.xml
xmlns:app="http://schemas.android.com/a android:layout_below="@+id/editTextRec
pk/res-auto" ordNum"
xmlns:tools="http://schemas.android.com/t android:layout_alignLeft="@+id/editText
ools" RecordNum"
android:layout_width="match_parent" android:layout_marginStart="44dp"
android:layout_height="match_parent" android:layout_marginLeft="44dp"
tools:context=".MainActivity"> android:layout_marginTop="44dp"
<EditText
android:fontFamily="@font/poppins_medi
android:id="@+id/editTextRecordNum" um"
android:layout_width="318dp" android:text="Normal Insert"
android:layout_height="50dp"
app:layout_constraintStart_toStartOf="par
android:layout_alignParentLeft="true" ent"
android:layout_alignParentTop="true" app:layout_constraintTop_toBottomOf="
android:layout_marginStart="44dp" @+id/editTextRecordNum" />
android:layout_marginLeft="44dp" <Button
android:layout_marginTop="124dp" android:id="@+id/buttonFastInsert"
android:ems="10"
android:layout_width="wrap_content"
android:fontFamily="@font/poppins_medi
um" android:layout_height="wrap_content"
android:inputType="number"
android:singleLine="true" android:layout_alignBaseline="@+id/butt
android:textColor="#FFFFFF" onNormalInsert"
app:layout_constraintStart_toStartOf="par android:layout_alignBottom="@+id/butto
ent" nNormalInsert"
android:layout_marginTop="44dp"
app:layout_constraintTop_toTopOf="pare android:layout_marginEnd="48dp"
nt" android:layout_marginRight="48dp"
tools:ignore="MissingConstraints" />
<Button android:layout_toRightOf="@+id/buttonN
ormalInsert" android:layout_alignLeft="@+id/buttonNo
rmalInsert"
android:fontFamily="@font/poppins_medi android:layout_marginStart="16dp"
um" android:layout_marginLeft="16dp"
android:text="Fast Insert" android:layout_marginTop="36dp"
app:layout_constraintEnd_toEndOf="pare android:fontFamily="@font/poppins_medi
nt" um"
android:padding="10dp"
app:layout_constraintTop_toBottomOf=" android:text="Status"
@+id/editTextRecordNum" /> android:textColor="#FFFFFF"
<TextView android:textSize="18sp"
android:id="@+id/textViewStatus"
app:layout_constraintStart_toStartOf="par
android:layout_width="wrap_content" ent"
android:layout_height="wrap_content" app:layout_constraintTop_toBottomOf="
@+id/buttonNormalInsert" />
android:layout_below="@+id/buttonNorm </androidx.constraintlayout.widget.Constr
alInsert" aintLayout>
2. MainActivity.java
3. DatabaseHandler.java
Ans 3) EditText is used for user input. TextView is used to display text and is not
editable by the user. TextView is the widget used when you want the user to View
the Text (such as a label, etc) and EditText used when you want the user to be able to
edit the text.
X. Exercise
Note: Faculty must ensure that every group of students use different input
values.
(Use blank space for answers or attach more pages if needed)
1. Write a program to create the login form with necessary validations like length of
username and password, empty text fields, count of unsuccessful login attempts.
Display the login successful/Unsuccessful toastmessage.
android:layout_alignParentLeft="true" android:layout_below="@+id/User_passw
ord"
android:layout_alignParentEnd="true"
android:layout_centerHorizontal="true"
android:layout_alignParentRight="true" android:layout_marginTop="25dp"
android:layout_marginStart="49dp" android:text="Login" />
android:layout_marginLeft="49dp" <EditText
android:layout_marginTop="25dp" android:id="@+id/User_email"
android:layout_marginEnd="53dp" android:layout_width="310dp"
android:layout_marginRight="53dp"
android:ems="10" android:layout_height="wrap_content"
android:hint="Password:"
android:inputType="textPassword" android:layout_below="@+id/User_Text"
android:padding="10dp" />
<TextView
android:id="@+id/User_Text" android:layout_alignParentStart="true"
android:layout_width="wrap_content" android:layout_alignParentLeft="true"
android:layout_height="wrap_content" android:layout_alignParentEnd="true"
android:layout_alignParentTop="true" android:layout_alignParentRight="true"
android:layout_marginStart="49dp"
android:layout_alignParentEnd="true" android:layout_marginLeft="49dp"
android:layout_marginTop="80dp"
android:layout_alignParentRight="true" android:layout_marginEnd="52dp"
android:layout_marginTop="113dp" android:layout_marginRight="52dp"
android:layout_marginEnd="106dp" android:hint="Email:"
android:layout_marginRight="106dp"
android:inputType="textEmailAddress"
android:fontFamily="@font/poppins_semi android:padding="10dp" />
bold" </RelativeLayout>
android:text="User Login"
2. MainActivity.java
3. activity_main2.xml
5. MainActivity2.java
package com.example.coexp28;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity2 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
}}
5. AndroidMainfest.xml
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.COEXP28">
<activity android:name=".MainActivity2"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
X. Exercise
Note: Faculty must ensure that every group of students use different input value.
(Use blank space for answers or attach more pages if needed)
1. Write a program to send and receive SMS, make use of the following GUI.
Ans1) 1. activity_main.xml
android:background="@color/cardview_s <Button
hadow_start_color"/> android:id="@+id/bt_send"
<EditText android:layout_width="wrap_content"
android:id="@+id/et_message"
android:layout_height="wrap_content"
android:layout_width="match_parent" android:text="Send SMS"
android:layout_marginTop="32dp"/>
android:layout_height="wrap_content"
android:hint="Enter Message" </LinearLayout>
2. MainActivity.java
package com.example.coexp29;
import androidx.annotation.NonNull; EditText etPhone, etMessage;
import Button btSend;
androidx.appcompat.app.AppCompatActiv
ity; @Override
import androidx.core.app.ActivityCompat; protected void onCreate(Bundle
import savedInstanceState) {
androidx.core.content.ContextCompat; super.onCreate(savedInstanceState);
sendMessage(); @Override
}else{ public void
onRequestPermissionsResult(int
ActivityCompat.requestPermissions(Main requestCode, @NonNull
Activity.this, new @org.jetbrains.annotations.NotNull
String[]{Manifest.permission.SEND_SMS
String[] permissions, @NonNull
}, 100);
@org.jetbrains.annotations.NotNull int[]
}
grantResults) {
}
});
super.onRequestPermissionsResult(request
}
Code, permissions, grantResults);
private void sendMessage() {
if (requestCode == 100 &&
String sPhone =
grantResults.length > 0 &&
etPhone.getText().toString().trim();
grantResults[0]
String sMessage =
==
etMessage.getText().toString().trim();
PackageManager.PERMISSION_GRANTE
D){
if (!sPhone.equals("") &&
!sMessage.equals("")){ sendMessage();
SmsManager smsManager = }else{
SmsManager.getDefault();
Toast.makeText(getApplicationContext(),
smsManager.sendTextMessage(sPhone, "Permission Denied!",
null, sMessage, null, null); Toast.LENGTH_SHORT).show();
}
}
Toast.makeText(getApplicationContext(), }
"SMS sent successfully!",
3. AndroidManifest.xml
android:roundIcon="@mipmap/ic_launcher_ro
und"
android:supportsRtl="true"
android:theme="@style/Theme.COEXP29">
<activity android:name=".MainActivity">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUN
CHER" />
</intent-filter>
</activity>
</application>
</manifest>
XI. References / Suggestions for further Reading
1. https://www.tutorialspoint.com/android
2. https://stuff.mit.edu
3. https://www.tutorialspoint.com/android/android_advanced_tutorial.pdf
4. https://developer.android.com
X. Exercise
Note: Faculty must ensure that every group of students use different input
value.
(Use blank space for answers or attach more pages if needed)
1. Write a program to send email.
Ans1) 1. Activity_main.xml
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="To:"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:id="@+id/edit_text_to"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Subject:"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:id="@+id/edit_text_subject"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailSubject" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Message:"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:id="@+id/edit_text_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start|top"
android:lines="10" />
<Button
android:id="@+id/button_send"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="send" />
</LinearLayout>
2. MainActivity.java
package com.example.coexp30;
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;
mEditTextTo = findViewById(R.id.edit_text_to);
mEditTextSubject = findViewById(R.id.edit_text_subject);
mEditTextMessage = findViewById(R.id.edit_text_message);
Ans1) 1. activity_main.xml
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/google_map"
android:name="com.google.android.gms.maps.SupportMapFragment"
/>
</RelativeLayout>
2. build.gradle (:app)
plugins { buildTypes {
id 'com.android.application' release {
} minifyEnabled false
proguardFiles
android { getDefaultProguardFile('proguard-android-
compileSdkVersion 30 optimize.txt'), 'proguard-rules.pro'
buildToolsVersion "30.0.3" }
}
defaultConfig { compileOptions {
applicationId "com.example.coexp31" sourceCompatibility
minSdkVersion 17 JavaVersion.VERSION_1_8
targetSdkVersion 30 targetCompatibility
JavaVersion.VERSION_1_8
versionCode 1 }
versionName "1.0" }
testInstrumentationRunner dependencies {
"androidx.test.runner.AndroidJUnitRunner"
} implementation
'androidx.appcompat:appcompat:1.3.0' implementation
implementation 'com.google.android.gms:play-services-
'com.google.android.material:material:1.3.0' location:18.0.0'
implementation testImplementation 'junit:junit:4.+'
'androidx.constraintlayout:constraintlayout:2.0. androidTestImplementation
4' 'androidx.test.ext:junit:1.1.2'
implementation androidTestImplementation
'com.google.android.gms:play-services- 'androidx.test.espresso:espresso-core:3.3.0'
maps:17.0.1' }
3. strings.xml
<resources>
<string name="app_name">COEXP31</string>
<string name="map_key"
translatable="false">AIzaSyB_qsP8AOP_P0MdlPz-48TDaJYjTP3vbjo</string>
</resources>
4. MainActivity.java
5. AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.COEXP31">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/map_key"/>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
ianistan Islamabad JAMMU AND
KASHMIR
Lahore,°
°UNJA9
Pakistan UTTARAKHAND
HAR’7ANA
GUJARA+ Ahmedabad
India
Ur
Mumbai / AHARASHTFA
*ELANGANA
Hyderabad
ANOHRA
KAPNATAkA PRADESD
Bengaluru
KEPALA
Sri Lan
19.043085172.8572711
Google Google
Ans1) 1. activity_main.xml
2. MainActivity.java
package com.example.coexp32;
import androidx.appcompat.app.AppCompatActivity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText etSource,etDestination;
Button btTrack;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etSource = findViewById(R.id.et_source);
etDestination = findViewById(R.id.et_destination);
btTrack = findViewById(R.id.bt_track);
btTrack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String sSource = etSource.getText().toString().trim();
String sDestination = etDestination.getText().toString().trim();
if(sSource.equals("") && sDestination.equals("")){
Toast.makeText(MainActivity.this, "Enter both location",
Toast.LENGTH_SHORT).show();
}else{
DisplayTrack(sSource,sDestination); }}}); }
private void DisplayTrack(String sSource, String sDestination) {
try{