Mad Solved Manual
Mad Solved Manual
Mad Solved Manual
Roll N
Exam Seat
‹,(22617)”
Ans 2:
Android studio Komodo
Eclipse Cordovo
IntelliJ Idea
Netbeans
Visual Studio
Ans 1:
JVM is the virtual machine that runs java code on different platforms. It acts as an
abstract layer between the program and the platform on which the java code is
running. The portability of Java code is possible only because of the JVM. The javac
compiler converts the source code file(.java file) into an intermediate java
bytecode format which is machine/platform independent.
DVM is a virtual machine to execute Android applications. The Java bytecode(.class
file) generated by javac compiler is converted into Dalvik bytecode to make the
application source files executable on the DVM. Since Android devices have a
definite processing capacity, memory, and battery life, the DVM design principle
aims to optimize itself so Ans it can load fastly and run smoothly even on low
memory/powered devices
Ans 2:
An IDE, or Integrated Development Environment, enables programmers to consolidate
the different aspects of writing a computer program. IDEs increase programmer
productivity by combining common activities of writing software into a single
application: editing source code, building executables, and debugging
Dated signature of
Marks Obtained
Teacher
Process Product Total
Related(10) Related(15) (25)
I. Practical Significance
Configuration set up steps should be known beforehand as learnt in the practical no.2
Android Development Tools (ADT) is a plugin for the Android studio that is designed
to give you a powerful, integrated environment in which to build Android applications.
ADT extends the capabilities of Android studio to let you quickly set up new Android
projects, create an application UI, add components based on the Android Framework
API, debug your applications using the Android SDK tools, and even export signed (or
unsigned) APKs in order to distribute your application. Developing in Android studio
with ADT is highly recommended and is the fastest way to get started. With the
guided project setup, it provides, as well as tools integration, custom XML editors, and
debug output pane, ADT gives you an incredible boost in developing Android
applications.
The ADT Bundle includes everything you need to begin developing apps:
Android studio + ADT plugin
Android SDK Tools Android Platform-tools
The latest Android platform
The latest Android system image for the emulator
Ans 2:
Android uses Dalvik Virtual Machine (DVM) which requires a special bytecode. We need
to convert Java class files into Dalvik Executable files using an Android tool called "dx".
In normal circumstances, developers will not be using this tool directly and build tools will
care for the generation of DVM compatible files.
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. What is a Build Type in Gradle?
2. Explain the build process in Android.
Ans 2:
The build process for a typical Android app module, as shown in figure 1, follows these
general steps:
1. The compilers convert your source code into DEX (Dalvik Executable) files,
which include the bytecode that runs on Android devices, and everything else into
compiled resources.
2. The APK Packager combines the DEX files and compiled resources into a single
APK. Before your app can be installed and deployed onto an Android device,
however, the APK must be signed.
3. The APK Packager signs your APK using either the debug or release keystore:
a. If you are building a debug version of your app, that is, an app you intend only for
testing and profiling, the packager signs your app with the debug keystore.
Android Studio automatically configures new projects with a debug keystore.
b. If you are building a release version of your app that you intend to release
externally, the packager signs your app with the release keystore. To create a
release keystore, read about signing your app in android studio.
4. Before generating your final APK, the packager uses the zipline tool tool to
optimize your app to use less memory when running on a device.
Dated signature of
Marks Obtained
Teacher
Process Product Total
Related(10) Related(15) (25)
I. Practical Significance
In android studio students must be aware of the directory structure and the control
flow of the program. Program should be either executed on the android mobile phones
or on the suitable emulators. To execute a simple program, like to display Hello World
on screen syntax of writing a program in android is pre-requisite as the programming
language used is JAVA only. The main activity code is a Java file MainActivity.java.
This is the actual application file which ultimately gets converted to a Dalvik executable
and runs your application.
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.activity_main,menu);
return true;
}
}
The Manifest File: Whatever component you develop as a part of your application, you
must declare all its components in a manifest file called AndroidManifest.xml which
resides at the root of the application project directory. This file works as an interface
between Android OS and your application, so if you do not declare your component in
this file, then it will not be considered by the OS. The <activity> tag is used to specify
an activity and android:name attribute specifies the fully qualified classname of the
Activity subclass and the android:label attributes specifies a string to useas the label
for the activity. You can specify multiple activities using <activity> tags. The action for
the intent filter is named android.intent.action.MAIN to indicate thatthis activity
serves as the entry point for the application. The category for the intent- filter is named
android.intent.category.LAUNCHER to indicate that the applicationcan be launched
from the device's launcher icon. The @string refers to the strings.xml file explained
below. Hence, @string/app_name refers to the app_name string defined in the
strings.xml file, which is "HelloWorld". Similar way, other strings get populatedin the
application. Following is the list of tags which you will use in your manifest file to
specify different Android application components:
1) <activity>elements for activities
2) <service> elements for services
3) <receiver> elements for broadcast receivers
4) <provider> elements for content providers
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
<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>
Dated signature of
Marks Obtained
Teacher
I. Practical Significance
To develop and place the android components accurately on the display
screen, android provides various layout managers. Layout managers can be
used on the simple android program too. Various layout managers can be
selected as per the program requirements.
Linear Layout: -
Ans. 1.
1. Linear Layout
LinearLayout is a view group that aligns all children in a single direction, vertically or
horizontally.
2. Relative Layout
RelativeLayout is a view group that displays child views in relative positions.
3. Table Layout
TableLayout is a view that groups views into rows and columns.
Ans. 2.
CardView is a new widget in Android that can be used to display any sort of data by
providing a rounded corner layout along with a specific elevation. CardView is the view
that can display views on top of each other. The main usage of CardView is that it helps to
give a rich feel and look to the UI design.
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
<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>
1……………………...
2……………………...
3………………………
4……………………….
Dated signature of
Marks Obtained
Teacher
Process Product Total
Related(10) Related(15) (25)
I. Practical Significance
To develop and place the android components accurately on the display
screen, android provides various layout managers. Layout managers can be
used on the simple android program too. Various layout managers can be
selected as per the program requirements.
2. Relative Layout:
A Relative Layout is a very powerful utility for designing a user interface because
it can eliminate nested view groups and keep your layout hierarchy flat, which
improves performance. If you find yourself using several nested Linear Layout
groups, you may be able to replace them with a single Relative Layout.
3. Table Layout:
A Table Layout consists of a number of Table Row objects, each defining a row
(actually, you can have other children, which will be explained below). Table
Layout containers do not display border lines for their rows, columns, or cells.
Each row has zero or more cells; each cell can hold one View object. The table has
as many columns as the row with the most cells. A table can leave cells empty. Cells
can span columns,as they can in HTML. The width of a column is defined bythe row
with the widest cell in that column.
Ans 1:
i. android:layout_width:This is the width of the layout.
ii. android:layout_height:This is the height of the layout
iii. android:layout_x:This specifies the x-coordinate of the layout.
iv. android:layout_y:This specifies the y-coordinate of the layout.
v. android:padding: This is the padding of the layout.
vi. android:margin: This is the margin of the layout
Ans 2 :
A layout that places its children in a rectangular grid.
The grid is composed of a set of infinitely thin lines that separate the viewing area into cells.
Throughout the API, grid lines are referenced by grid indices. A grid with N columns has N +
Maharashtra State Board of Technical Education 34
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
<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
<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
<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
<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
<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
<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>
Dated signature of
Marks Obtained
Teacher
Process Product Total
Related(10) Related(15) (25)
Practical No. 7: Develop a program to implement Text View and Edit Text.
I. Practical Significance
In this practical, UI controls in android like Text view and edit view are
studied. Wherein the UI controls can be developed, used and placed on the
screen using different layout managers as per the problem statement
requirements.
1. Text View:
In Android, Text View displays text to the user and optionally allows them to edit it
programmatically. Text View is a complete text editor, however basic class is
configured to not allow editing but we can edit it. View is the parent class of Text
View Being a subclass of view the text view component can be used in your app’s.
GUI inside a View Group, or as the content view of an activity. We can create a Text
View instance by declaring it inside a layout(XML file) or by instantiating it
programmatically(Java Class).
2. Edit Text:
In Android, Edit Text is a standard entry widget in android apps. It is an overlay over
Text View that configures itself to be editable. Edit Text is a subclass of Text View
with text editing operations. Often use Edit Text in our applications in order to
provide an input or text field, especially in forms. The simplest example of Edit Text
is Login or Sign-in form. Text Fields in Android Studio are basically Edit Text.
Note: An Edit Text is simply a thin extension of a Text View. An Edit Text
inherits all the properties of a Text View.
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);
}
}
Dated signature of
Marks Obtained
Teacher
Process Product Total
Related(10) Related(15) (25)
I. Practical Significance
In this practical, UI controls in android like Buttons are studied. There are various
types of buttons like Image button and toggle button which is studied.
2. Types of buttons–
Buttons can be divided into two categories the first is Buttons with text on, and
second is buttons with an image on.
3. Image Button –
A button with images on can contain both an image and a text. Android buttons with
images on are also called Image Button. In Android, Image Button is used to display
a normal button with a custom image in a button. In simple words we can say, Image
Button is a button with an image that can be pressed or clicked by the users. By
default it looks like a normal button with the standard button background that
changes the color during different button states. An image on the surface of a button
is defined within a xml (i.e. layout ) by using src attribute or within java class by
using setImageResource() method. We can also set an image or custom drawable in
the background of the image button . Image Button has all the properties of a normal
button so you can easily perform any event like click or any other event which you
can perform on a normal button.
Note: Standard button background image is displayed in the background of button
whenever you create an image button. To remove that image, you can define your
own background image in xml by using background attribute or in java class by
using setBackground() method.
4. Toggle Button–
A toggle button allows the user to change a setting between two states. You can
add a basic toggle button to your layout with the Toggle Button object. If you need
to change a button's state yourself, you can use the Compound
setOnCheckedChangeListener().
It is beneficial if user have to change the setting between two states. It can be used
to On/Off Sound, Wi-Fi, Bluetooth etc. By default, the android Toggle Button will
be in OFF (Unchecked) state. We can change the default state of Toggle Button by
using android:checked attribute. In case, if we want to change the state of Toggle
Button to ON (Checked), then we need to set android:checked = “true” in our
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
Dated signature of
Marks Obtained
Teacher
Process Product Total
Related(10) Related(15) (25)
I. Practical Significance
In this practical, all the previous UI controls in android like Text View, Edit Text
Buttons which are studied are implemented in this practical. Events are also handled
on the android UI controls used in the practical.
Define a button with login text and set its onClick Property. After that define the
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
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
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
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
/> 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
Toast.makeText(MainActivity.this }
,"Semester "+Semester });
,Toast.LENGTH_SHORT).show()
; }
}
Intent intent=new
Output:
Dated signature of
Marks Obtained
Teacher
Process Product Total
Related(10) Related(15) (25)
2. Radio buttons allow the user to select one option from a set. You should use radio
buttons for optional sets that are mutually exclusive if you think that the user needs
to see all available options side-by-side.
X. Exercise
Note: Faculty must ensure that every group of students use different examples.
(Use blank space for answers or attach more pages if needed)
1. Write a program to show the following output. First two radio buttons are without
using radio group and next two radio buttons are using radio group. Note
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
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()
Dated signature
Marks Obtained
of
Teacher
Process Product Total (25)
Related(10) Related(15)
I. Practical Significance
Progress bars are used to show progress of a task. For example, when you are uploading
or downloading something from the internet, it is better to show the progress of
download/upload to the user. In android there is a class called Progress Dialog that
allows you to create progress bar.
Ans1) You can update the percentage of progress displayed by using the
setProgress(int) method, or by calling incrementProgressBy(int) to increase the
current progress completed by a specified amount. By default, the progress bar is
full when the progress value reaches 100. You can adjust this default by setting the
android:max attribute.
Ans 2) <ProgressBar
android:id="@+id/indeterminateBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
Ans 3) XML attributes
1. android:indeterminateTintMode
2. android:interpolator
3. android:max
4. android:maxHeight
5. android:maxWidth
6. android:min
android:minHeight
Dated signature of
Marks Obtained
Teacher
Process Product Total
Related(10) Related(15) (25)
I. Practical Significance
A View occupies a rectangular area on the screen and is responsible for drawing and
event handling. View is the base class for widgets, which are used to create interactive
UI components (buttons, text fields, etc.). The View Group subclass is the base class for
layouts, which are invisible containers that hold other Views (or other ViewGroups) and
define their layout properties.
.
II. Relevant Program Outcomes (POs)
PO 1. Basic knowledge
PO 2- Discipline knowledge
PO 3- Experiments and practice
PO 4- Engineering tools
Grid View
In android Grid View is a view group that display items in two dimensional scrolling
grid (rows and columns), the grid items are not necessarily predetermined but they are
automatically inserted to the layout using a List Adapter. Users can then select any
grid item by clicking on it. Grid View is default scrollable so we don’t need to
use Scroll View or anything else with Grid View.
Image View
In Android, Image View class is used to display an image file in application. Image
file is easy to use but hard to master in Android, because of the various screen sizes in
Android devices. An android is enriched with some of the best UI design widgets that
allows us to build good looking and attractive UI based application.
Scroll Vie
In android scroll View can hold only one direct child. This means that, if you have
complex layout with more views(Buttons, Text Views or any other view) then you
must enclose them inside another standard layout like Table Layout, Relative
Layout or Linear Layout. You can specify layout_width and layout_height to adjust
width and height of screen. You can specify height and width in dp(density pixel) or
px(pixel). Then after enclosing them in a standard layout, enclose the whole layout
in scroll View to make all the element or views scrollable.
</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
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
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
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"
Downloaded by Sayali Mundhe ([email protected])
lOMoARcPSD|36448089
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
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
I. Practical Significance
An activity represents a single screen with a user interface. For example, an email
application might have one activity that shows a list of new emails, another activity to
compose an email, and one for reading emails.
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*Code goes here*/
}
/** Called when the activity is about to
become visible. */ @Override
protected void onStart() { super.onStart();
/*Code goes here*/
}
/** Called when the activity has
become visible. */ @Override
protected void onResume() { super.onResume();
/*Code goeshere*/
}
/** Called when another activity is
taking focus. */ @Override
protected void
onPause() {
super.onPause();
/*Code goes here*/
}
/** Called when the activity is no
longer visible. */ @Override
protected void onStop() { super.onStop();
/*Code goes here*/
}
/** Called just before the activity is
destroyed. */ @Override
public void onDestroy() { super.onDestroy();
/*Code goes here*/
}
}
Ans 1:
Ans 2: All graphics, strings, layouts, and other resource files are stored in the resource
file hierarchy under the res directory.
Ans 3:
Once onStop() is called then onRestart() can be called. onDestroy() is last in the order after
onStop(). onDestory() is called just before an activity is destroyed and after that it is gone it is not
possible to resurrect this.
onPause() is called when the activity is still in the screen, once the method execution is completed
then the activity loses focus. So, onPause() is logically before onStop(). From onPause() it is
possible to call onResume() but it is not possible once onStop() is called.
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
@Override
protected void onRestart(){
super.onRestart();
Log.d("lifecycle","onRestart
invoked");
}
@Override
protected void onDestroy(){
super.onDestroy();
Log.d("lifecycle","onDestroy
invoked");
}
Output:
1 Gaurang Jadhav
2 Shweta Gupta
3 Heet Zatakia
Dated signature of
Marks Obtained
Teacher
Process Product Total
Related(15) Related(10) (25)
I. Practical Significance
Android Intent is the message that is passed between components such as activities,
content providers, broadcast receivers, services etc. It facilitates communication
between different android components
Types of intents:
There are two types of intents
a. Implicit Intent
b. Explicit Intent
Implicit Intent:
The implicit intent is the intent where instead of defining the exact components, you
define the action that you want to perform for different activities.
Syntax:
Intent i=new Intent();
i.setAction(Intent.ACTIO
N_SEND);
Explicit Intent:
An explicit intent is an Intent where you explicitly define the component
that needs to be called by the Android System. An explicit intent is one that
you can use to launch a specific app component, such as a particular activity
or service in your app.
Syntax:
Intent I = new
Intent(getApplicationContext(),NextActivity.class);
I.putExtra(“value1” , “This value for Next Activity”);
I.putExtra(“value2” , “This value for Next Activity”);
Ans 2:
Intent i = new Intent(Intent.ACTION_DIAL, u); Context.startActivity(i)
X. Exercise
(Solve any one of the following. Use blank space provide for answers or attached more pages if
needed)
1. Write a program to create a text field and a button “Navigate”. Whenyou enter
“www.google.com” and press navigate button it should open google page.
2. Write a program to create button “Start Dialer”. When u click on this button it
should open the phone dialer.
3. Write a program to create two screens. First screen will take one numberinput from
user. After click on Factorial button, second screen will openand it should display
factorial of the same number. Also specify which type of intent you will use in this
case.
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
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
4 Gaurang Jadhav
5 Shweta Gupta
6 Heet Zatakia
Dated signature of
Marks Obtained
Teacher
Process Product Total
Related(15) Related(10) (25)
I. Practical Significance
Broadcast Receivers simply respond to broadcast messages from other applications or
from the system. For example, applications can also initiate broadcasts to let other
applications know that some data has been downloaded to the device and is available
for them to use, so this is broadcast receiver who will intercept this communication
and will initiate appropriate action.
Ans 1) Broadcasting Intents are different from the Intents used to start an Activity or a Service
(discussed in previous Android Tutorials). The intent used to start an Activity makes
changes to an operation the user is interacting with, so the user is aware of the process.
However, in case of broadcasting intent, the operation runs completely in the background,
and is therefore invisible to the user.
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
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>
1 Gaurang Jadhav
2 Shweta Gupta
3 Heet Zatakia
Dated signature of
Marks Obtained
Teacher
Process Product Total
Related(10) Related(15) (25)
I. Practical Significance
Most of the android devices have built-in sensors that measure motion, orientation,
and various environmental condition. Android allows us to get the raw data from these
sensors and use it in our application.
The next thing you need to do is to instantiate the object of Sensor class by calling the
getDefaultSensor() method of the SensorManager class. Its syntax is given below:
Sensor light;
light = sMgr.getDefaultSensor(Sensor.TYPE_LIGHT);
Once that sensor is declared, you need to register its listener and override two methods
which are onAccuracyChanged and onSensorChanged. Its syntax is as follows:
sMgr.registerListener(this, light,SensorManager.SENSOR_DELAY_NORMAL);
public void onAccuracyChanged(Sensor sensor, int accuracy)
{}
public void onSensorChanged(SensorEvent event) { }
Methods:
1. getDefaultSensor(int type) :- This method get the default sensor for a given type.
Explain methods
2. getOrientation(float[] R, float[] values) :- This method returns a description of the
current primary clip on the clipboard but not a copy of its data.
3. getInclination(float[] I) :- This method computes the geomagnetic inclination angle
in radians from the inclination matrix.
4. registerListener(SensorListener listener, int sensors, int rate) :-This method
registers a listener for the sensor
5. unregisterListener(SensorEventListener listener, Sensor sensor) :-This method
unregisters a listener for the sensors with which it is registered.
6. getOrientation(float[] R, float[] values) :-This method computes the device's
orientation based on the rotation matrix.
7. getAltitude(float p0, float p) :-This method computes theAltitude in meters from
the atmospheric pressure and the pressure at sea-level.
i. Unregister sensor listeners: Always make sure to disable sensors you don’t need,
especially when your activity is paused.
ii. Don’t block the onSensorChanged() method: Sensor data can change at a high rate,
which means the system may call the onSensorChanged(SensorEvent) method quite often.
As a best practice, you should do as little as possible within the onSensorChanged
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));
}
}
1 Gaurang Jadhav
2 Shweta Gupta
3 Heet Zatakia
Dated signature of
Marks Obtained
Teacher
Process Product Total
Related(10) Related(15) (25)
I. Practical Significance:
The Android framework includes support for various cameras and camera features
available on devices, allowing you to capture pictures and videos in your application.
We will be using the camera API to integrate the camera in our application. First you
will need to initialize the camera object using the static method provided by the api
called Camera. Open. Its syntax is:
Camera object = null;
object = Camera.open();
Methods:
1. startActivityForResult(Intent intent, int requestCode, Bundle options) It starts an
activity, but can take extra bundle of options withit.
2. startActivityFromChild(Activity child, Intent intent, int requestCode) It launches
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
1 Gaurang Jadhav
2 Shweta Gupta
3 Heet Zatakia
I. Practical Significance
Bluetooth is a way to send or receive data between two different devices. Android
platform includes support for the Bluetooth framework that allows a device to
wirelessly exchange data with other Bluetooth devices.
In order to enable the Bluetooth of your device, call the intent with the following
Bluetooth constant ACTION_REQUEST_ENABLE. Its syntax is.
Intent turnOn = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(turnOn, 0);
Once you enable the Bluetooth, you can get a list of paired devices by calling
getBondedDevices() method. It returns a set of Bluetooth devices. Its syntax is.
private
Set<BluetoothDevice>pairedDevi
ces; pairedDevices =
BA.getBondedDevices();
Ans 1) enable() and disable() methods are used to enable and disable Bluetooth adapters.
Ans 2) ACTION_REQUEST_DISCOVERABLE constant is used for turn on discovery of
bluetooth.
Ans 3) T he setName() method provided by java. lang. Thread class is used to change the name of
the thread and setName assigns a name to an object.
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 turn on, get visible, list devices and turnoff
Bluetooth with the help of following GUI.
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
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
Android_Manifest.xml
1 Gaurang Jadhav
2 Shweta Gupta
3 Heet Zatakia
Dated signature of
Marks Obtained
Teacher
Process Product Total
Related(10) Related(15) (25)
I. Practical Significance
Bluetooth is a way to send or receive data between two different devices. Android
platform includes support for the Bluetooth framework that allows a device to wirelessly
exchange data with other Bluetooth devices.
In order to enable the Bluetooth of your device, call the intent with the following Bluetooth
constant ACTION_REQUEST_ENABLE. Its syntax is.
Intent turnOn = new
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(turnOn, 0);
Once you enable the Bluetooth, you can get a list of paired devices by calling
getBondedDevices() method. It returns a set of Bluetooth devices. Its syntax is.
private
Set<BluetoothDevice>pairedDevi
ces; pairedDevices =
BA.getBondedDevices();
Ans 3) The setName() method provided by java. lang. Thread class is used to
change the name of the thread and setName assigns a name to an object.
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 turn on, get visible, list devices and turn off
Bluetooth with the help of following GUI.
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>
Dated signature of
Marks Obtained
Teacher
Process Product Total
Related(10) Related(15) (25)
I. Practical Significance
Android AsyncTask is an abstract class provided by Android which gives us the liberty
to perform heavy tasks in the background and keep the UI thread light thus making the
application more responsive.
Ans 2) In some cases it is possible to accomplish the same task with either an
AsyncTask or a Service however usually one is better suited to a task than the other.
AsyncTasks are designed for once-off time-consuming tasks that cannot be run on the
UI thread. A common example is fetching/processing data when a button is pressed.
Services are designed to be continually running in the background. In the example
above of fetching data when a button is pressed, you could start a service, let it fetch
the data, and then stop it, but this is inefficient. It is far faster to use an AsyncTask
that will run once, return the data, and be done.
If you need to be continually doing something in the background, though, a Service
is your best bet. Examples of this include playing music, continually checking for new
data, etc.
Ans 3) AsyncTasks should ideally be used for short operations (a few seconds at the
most.) If you need to keep threads running for long periods of time, it is highly
recommended you use the various APIs provided by the java.util.concurrent package
such as Executor, ThreadPoolExecutor and FutureTask.
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
context) { }
super(context, DATABASE_NAME, db.setTransactionSuccessful();
null, DATABASE_VERSION);
} db.endTransaction();
db.close();
// creating table
@Override }
// inserts the record without using
public void onCreate(SQLiteDatabase
db) { transaction and prepare statement
String sql = "";
sql += "CREATE TABLE " + public void insertNormal(int
tableName; insertCount){
sql += " ( "; try{
sql += fieldObjectId + " INTEGER SQLiteDatabase db =
this.getWritableDatabase();
PRIMARY KEY AUTOINCREMENT, ";
sql += fieldObjectName + " TEXT, "; for(int x=1; x<=insertCount; x++){
sql += fieldObjectDescription + " ContentValues values = new
TEXT "; ContentValues();
values.put(fieldObjectName,
sql += " ) ";
db.execSQL(sql); "Name # " + x);
String INDEX = "CREATE UNIQUE
values.put(fieldObjectDescription,
INDEX locations_index ON "
+ tableName + " (name, "Description # " + x);
description)"; db.insert(tableName, null,
db.execSQL(INDEX); values);
} }
// When upgrading the database, it will db.close();
drop the current table and recreate. }catch(Exception e){
@Override e.printStackTrace();
public void onUpgrade(SQLiteDatabase }}
db, int oldVersion, int newVersion) { // deletes all records
String sql = "DROP TABLE IF public void deleteRecords(){
EXISTS " + tableName; SQLiteDatabase db =
db.execSQL(sql); this.getWritableDatabase();
onCreate(db); db.execSQL("delete from "+
} tableName);
// insert data using transaction and db.close();
prepared statement }
public void insertFast(int insertCount) { // count records
// you can use INSERT only public int countRecords(){
String sql = "INSERT OR REPLACE SQLiteDatabase db =
INTO " + tableName + " ( name, this.getWritableDatabase();
description ) VALUES ( ?, ? )"; Cursor cursor =
SQLiteDatabase db = db.rawQuery("SELECT count(*) from " +
this.getWritableDatabase(); tableName, null);
db.beginTransactionNonExclusive(); cursor.moveToFirst();
// db.beginTransaction(); int recCount = cursor.getInt(0);
SQLiteStatement stmt = cursor.close();
db.compileStatement(sql); db.close();
for(int x=1; x<=insertCount; x++){ return recCount;
stmt.bindString(1, "Name # " + x); }}
stmt.bindString(2, "Description # "
+ x);
stmt.execute();
stmt.clearBindings();
Dated signature of
Marks Obtained
Teacher
Process Product Total
Related(10) Related(15) (25)
Practical No. 28: Create login application where you will have to validate
username and password till the username and password
is not validated, login button should remain disabled.
I. Practical Significance
Today Login and Registration form in Android are part of every application out there.
So, when we are programming, we work with many registration forms. Forms can be
very different from a simple login or registration to a complex ordering form for any
application.
Ans 2) Various GUI components used to design the login form with validation are as
follows:
1. Add the first EditText for the first name.
a. Name it "firstName" (use the id attribute to name the component).
b. Set text to "".
c. Set the hint to "First name".
d. This one should have 3 constraints; one links to the top of the screen, second
to left border and third to the right border.
2. Add EditText for the last name.
a. Name it "lastName".
b. Set text to "".
c. Set the hint to "First name".
d. This one should have 3 constraints; one linked to the bottom of "First name",
second to left border and third to the right border.
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:textColor="#FFFFFF"
android:layout_height="wrap_content" android:textSize="40dp" />
<Button
android:layout_below="@+id/User_email" android:id="@+id/User_login"
android:layout_width="150dp"
android:layout_alignParentStart="true"
android:layout_height="wrap_content"
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
else{ ;
Toast.makeText(this,"Wrong email }
or }
password",Toast.LENGTH_LONG).show() }
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>
Dated signature of
Marks Obtained
Teacher
Process Product Total
Related(10) Related(15) (25)
Practical No. 29: Develop a program to: a) Send SMS b) Receive SMS
I. Practical Significance
Android devices can send and receive messages to or from any other phone that supports
Short Message Service (SMS). Android offers the Messenger application that can send
and receive SMS messages.
To receive SMS messages, the best practice is to use the onReceive() method of the
Broadcast Receiver class. The Android framework sends out system broadcasts of
events such as receiving an SMS message, containing intents that are meant to be
received using a Broadcast Receiver. Your app receives SMS messages by listening for
the SMS_RECEIVED_ACTION broadcast.
Methods :
1 ArrayList<String> divideMessage(String text) :-This method divides a message text
into several fragments, none bigger than the maximum SMS message size.
2 static SmsManager getDefault() :- This method is used to get the default instance of
the Sms Manager
3 void sendDataMessage(String destination Address, String scAddress, short
destinationPort, byte[] data, PendingIntent sentIntent, PendingIntent
deliveryIntent):- This method is used to send a data based SMS to a specific
application port.
4 void sendTextMessage(String destinationAddress, String scAddress, String text,
PendingIntent sentIntent, PendingIntent deliveryIntent) :-Send a text based SMS.
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:padding="12dp"
android:layout_width="match_parent" android:minLines="6"
android:inputType="textMultiLine"
android:layout_height="wrap_content" android:gravity="top"
android:hint="Enter Phone Number" android:layout_marginTop="8dp"
android:padding="12dp"
android:maxLength="10" android:background="@color/cardview_s
android:inputType="phone" hadow_start_color"/>
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);
if Toast.LENGTH_LONG).show();
(ContextCompat.checkSelfPermission(Mai }else{
nActivity.this
, Toast.makeText(getApplicationContext(),"
Enter value first.",
Manifest.permission.SEND_SMS)
Toast.LENGTH_SHORT).show();
== }
PackageManager.PERMISSION_GRANTE
D){ }
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>
Dated signature of
Marks Obtained
Teacher
Process Product Total
Related(10) Related(15) (25)
I. Practical Significance
To send email from your Android application, you have to write an Activity that needs
to launch an email client and send an email using your Android device. This practice
focuses on integrating the existing email clients in the new applications.
Ans 1) Before starting Email Activity, You must know Email functionality with
intent, Intent is carrying data from one component to another component with-in the
application or outside the application.
To send an email from your application, you don’t have to implement an email client
from the beginning, but you can use an existing one like the default Email app
provided from Android, Gmail, Outlook, K-9 Mail etc. For this purpose, we need to
write an Activity that launches an email client, using an implicit Intent with the right
action and data. In this example, we are going to send an email from our app by using
an Intent object that launches existing email clients.
Ans 2) Extra fields that can be used in an application to send emails are as follows:
EXTRA_EMAIL - It’s an array of email addresses
EXTRA_SUBJECT - The subject of the email that we want to send
EXTRA_TEXT - The body of the email
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);
@Override
public void onClick(View v) {
sendMail();
}
});
}
private void sendMail() {
String recipientList = mEditTextTo.getText().toString();
String[] recipients = recipientList.split(",");
String subject = mEditTextSubject.getText().toString();
String message = mEditTextMessage.getText().toString();
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, recipients);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, message);
intent.setType("message/rfc822");
startActivity(Intent.createChooser(intent, "Choose an email client"));
}
}
Dated signature of
Marks Obtained
Teacher
Process Product Total
Related(10) Related(15) (25)
I. Practical Significance
Android allows us to integrate google maps in our application. You can show any
location on the map, or can show different routes on the map. You can also customize
the map according to your choices.
/>
<uses-permission
android:name="com.google.android.providers.gsf.permission.
READ_GSERVICES" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STO
RAGE" />
Ans 1) The following map types are supported in Google Maps API:
1. ROADMAP (normal, default 2D map)
2. SATELLITE (photographic map)
3. HYBRID (photographic map + roads and city names)
4. TERRAIN (map with mountains, rivers, etc.)
The map type is specified either within the Map properties object, with the
mapTypeId property:
var mapOptions = {
center:new google.maps.LatLng(51.508742,-0.120850),
zoom:7,
mapTypeId: google.maps.MapTypeId.HYBRID
};
Or by calling the map's setMapTypeId() method:
map.setMapTypeId(google.maps.MapTypeId.HYBRID);
Ans 2) To enable or disable all interactive features, we use the interactivity() method.
Set true or false to the method depending if you'd like to enable the map interactivity
or disable it.
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 locate the user's current location.
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
tLocation.getLatitude()+""+currentLocation.get
Location currentLocation; Longitude(),Toast.LENGTH_SHORT).show();
FusedLocationProviderClient SupportMapFragment
fusedLocationProviderClient; supportMapFragment=(SupportMapFragment)
getSupportFragmentManager().findFragmentBy
private static final int REQUEST_CODE =
101; Id(R.id.google_map);
// SupportMapFragment
@Override supportMapFragment = (SupportMapFragment)
protected void onCreate(Bundle getSupportFragmentManager().findFragmentBy
savedInstanceState) { Id(R.id.google_map);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); supportMapFragment.getMapAsync(MainActiv
ity.this);
}
fusedLocationProviderClient = }
LocationServices.getFusedLocationProviderCli });
ent(this);//CLIENT REGISTER
}
fetchLastLocation();
}
@Override
private void fetchLastLocation() { public void onMapReady(GoogleMap
if googleMap) {
(ActivityCompat.checkSelfPermission(this, LatLng latLng = new
Manifest.permission.ACCESS_FINE_LOCATI LatLng(currentLocation.getLatitude(),currentLo
ON) != cation.getLongitude());
PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this, MarkerOptions markerOptions = new
Manifest.permission.ACCESS_COARSE_LOCA MarkerOptions().position(latLng).title("I am
TION) !=
here");
PackageManager.PERMISSION_GRANTED) {
break; }
} }
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>
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
Dated signature of
Marks Obtained
Teacher
Process Product Total
Related(10) Related(15) (25)
10. stopAnimation() : This method stops the camera animation if there is one in
progress
Ans 2) The Maps API provides a compass graphic which appears in the top left corner
of the map under certain circumstances. The compass will only ever appear when the
camera is oriented such that it has a non-zero bearing or non-zero tilt. When the user
clicks on the compass, the camera animates back to a position with bearing and tilt of
zero (the default orientation) and the compass fades away shortly afterwards. You can
disable the compass appearing altogether by calling
UiSettings.setCompassEnabled(boolean). However, you cannot force the compass
to always be shown.
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 draw a route between two locations.
Ans1) 1. activity_main.xml
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/et_destination" />
</androidx.constraintlayout.widget.ConstraintLayout>
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{
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}catch (ActivityNotFoundException e){
Uri uri =
Uri.parse("https://play.google.com/store/apps/details?id=com.google.android.apps.maps");
Intent intent= new Intent(Intent.ACTION_VIEW,uri);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}}}
Dated signature of
Marks Obtained
Teacher
Process Product Total
Related(10) Related(15) (25)