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

chapter wise notes

Uploaded by

Prachi More
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

chapter wise notes

Uploaded by

Prachi More
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 90

1 CHAPTER WISE IMPORTANT QUESTION BANK MOBILE

APPLICATION DEVELOPMENT CHAPTER NO 1


Q1 1. What Is Android?
Ans Android is an open source and Linux-based Operating System for mobile devices 2
such as smartphones and tablet computers. Android was developed by the Open M
Handset Alliance, led by Google, and other companies.

Android offers a unified approach to application development for mobile devices


which means developers need only develop for Android, and their applications
should be able to run on different devices powered by Android.

The first beta version of the Android Software Development Kit (SDK) was released
by Google in 2007 where as the first commercial version, Android 1.0, was released
in September 2008.

On June 27, 2012, at the Google I/O conference, Google announced the next
Android version, 4.1 Jelly Bean. Jelly Bean is an incremental update, with the
primary aim of improving the user interface, both in terms of functionality and
performance.

Q2 Enlist And Explain Features Of Android OS? 4


M
Ans 1) Beautiful UI:-Android OS basic screen provides a beautiful and intuitive
user interface.
2) Storage :- SQLite, a lightweight relational database, is used for data storage
purposes.
3) Storage :-SQLite, a lightweight relational database, is used for data storage
purposes.
4) Multi-tasking :- User can jump from one task to another and same time
various application can run simultaneously.
5) Multi-Language :- Supports single direction and bi-directional text.

Q3 What Is OHA? 2
M
The Open Handset Alliance (OHA) is a business alliance that was created for the
purpose of developing open mobile device standards. The OHA has approximately
80 member companies, including HTC, Dell, Intel, Motorola, Qualcomm and
Google. The OHA’s main product is the Android platform – the world’s most
popular smartphone platform.

1)OHA is consortium of 86 companies that have come together to develop open


standards for the mobile devices

2)It was established in November 2007 by Google and includes mobile hardware
manufactures(like samsung,HTC,motoroala)software application
developer(Google,infosys) mobile network providers(like AT&T,sprint )and chipset
makers(like nvidia,AMD,Realtek,Intel)

3)The main goal of OHA is to develop standards for mobile devices develop
standards for mobile devices they also promot innovation in mobile phones and
provides better experience for consumers at a low cost

Q4 Enlist Various Android Version (Any 4)? 2


M
Ans  Tiramisu (OS 13)
 Snow Cone (OS 12)
 Red Velvet Cake (OS 11)
 Quince Tart (OS 10)
 Pie (9.0)
 Oreo (8.0)
 Nougat (7.0)
 Marshmallow (6.0)

Q5 Enlist Tools To Develop Android Application? 2


M
Ans  Android Studio
 Android Debug Bridge (ADB)
 Eclipse
 Vysor
 FlowUp
 Stetho
 GameMaker Studio
 Gradle
 Android Asset Studio
 RAD Studio
 AVD Manager
 LeakCanary
 Unity 3D
 NimbleDroid
 Instabug

Q6 Define Android Ecosystem? 2


M
Ans Android ecosystem is nothing but the relationship between Users, 2
Developers/Programmers, and Hardware equipment makers, the Android ecosystem M
is nothing but the mutual dependence between Users, Developers, and equipment
makers. they are independent of each other so one cannot exist without the other.

The main block of the android ecosystem is

1. Android User 2. Developer 3.Equipment Maker

1)Android User (Users buy handsets and software Application):

Android users have more space for customizability for their android devices.
Android users are smarter than other users and they are perceived to have greater
levels of support. Android users are also more likely to prefer saving their cost and
love the openness of the platform also they like to customize their device. Android
users are fancier to prefer saving money and also android user like customizing their
android handset/device

2. Developers (sell Application):

Android Developers are the professional software developer in designing


applications as well as developing applications for Android. Some of the following
tasks where an android developer can play his role in the development of android
apps:

Design and build advanced applications for the android platform

Collaborate and define with development teams for design and deliver new cool
features.

Troubleshoot and fix bugs in new and existing applications for Users.

Evaluate and implement new development tools to work with outside data sources
and APIs.

3. Equipment Maker:

Android equipments are available in the market in a huge amount.

Smartwatches: A smartwatch is a handheld, wearable device that closely relates a


wristwatch or other time device. In addition to telling time, many smartwatches are
wireless connectivity oriented such as Bluetooth capable. The traditional watch
becomes, in effect, a wireless Bluetooth technology extending the capabilities of the
wearer's smartphone to the watch.

Smart TV: An Android TV box is a small computer that plugs into any TV and gives
the user the ability to stream content, locally and online. Apps can be downloaded
from the Google Play Store, installed, and do most anything a standard computer can
do from streaming videos to writing an email.

Smart Speakers: Smark speakers are booming in the market now, Smark speakers
like Google Home, Alexa, We can control our android device via voice using these
smart speakers.

E-Reader: E-Reader is a device used for reading e-books, digital newspapers, other
reading stuff.

Q7 Draw Android System Architecture? 4


M
Architecture
Linux kernel

At the bottom of the layers is Linux - Linux 3.6 with approximately 115 patches.
This provides a level of abstraction between the device hardware and it contains
all the essential hardware drivers like camera, keypad, display etc. Also, the kernel
handles all the things that Linux is really good at such as networking and a vast
array of device drivers, which take the pain out of interfacing to peripheral
hardware.

Libraries

On top of Linux kernel there is a set of libraries including open-source Web


browser engine WebKit, well known library libc, SQLite database which is a
useful repository for storage and sharing of application data, libraries to play and
record audio and video, SSL libraries responsible for Internet security etc.

Android Libraries

This category encompasses those Java-based libraries that are specific to Android
development. Examples of libraries in this category include the application
framework libraries in addition to those that facilitate user interface building,
graphics drawing and database access. A summary of some key core Android
libraries available to the Android developer is as follows −

 android.app − Provides access to the application model and is the


cornerstone of all Android applications.
 android.content − Facilitates content access, publishing and messaging
between applications and application components.
 android.database − Used to access data published by content providers
and includes SQLite database management classes.
 android.opengl − A Java interface to the OpenGL ES 3D graphics
rendering API.
 android.os − Provides applications with access to standard operating
system services including messages, system services and inter-process
communication.
 android.text − Used to render and manipulate text on a device display.
 android.view − The fundamental building blocks of application user
interfaces.
 android.widget − A rich collection of pre-built user interface components
such as buttons, labels, list views, layout managers, radio buttons etc.
 android.webkit − A set of classes intended to allow web-browsing
capabilities to be built into applications.Having covered the Java-based
core libraries in the Android runtime, it is now time to turn our attention to
the C/C++ based libraries contained in this layer of the Android software
stack.
Android Runtime

This is the third section of the architecture and available on the second layer from
the bottom. This section provides a key component called Dalvik Virtual Machine
which is a kind of Java Virtual Machine specially designed and optimized for
Android.

The Dalvik VM makes use of Linux core features like memory management and
multi-threading, which is intrinsic in the Java language. The Dalvik VM enables
every Android application to run in its own process, with its own instance of the
Dalvik virtual machine.

The Android runtime also provides a set of core libraries which enable Android
application developers to write Android applications using standard Java
programming language.

Application Framework

The Application Framework layer provides many higher-level services to


applications in the form of Java classes. Application developers are allowed to
make use of these services in their applications.

The Android framework includes the following key services −

 Activity Manager − Controls all aspects of the application lifecycle and


activity stack.
 Content Providers − Allows applications to publish and share data with
other applications.
 Resource Manager − Provides access to non-code embedded resources
such as strings, color settings and user interface layouts.
 Notifications Manager − Allows applications to display alerts and
notifications to the user.
 View System − An extensible set of views used to create application user
interfaces.

Applications

You will find all the Android application at the top layer. You will write your
application to be installed on this layer only. Examples of such applications are
Contacts Books, Browser, Games etc.

Q8 Compare Android OS With Any Other OS (Any 4 Points) 4M


Terms Android OS Windows OS
Developer Android was developed and Windows was developed and
owned by Google LLC. owned by Microsoft
Incorporation.
Android is specifically designed Windows is designed for PC of all
Devices
for mobile devices. companies.
Default
Android has a Graphical (Multi- Windows OS Graphical (Metro
User
touch) user interface. UI).
Interface
In windows phone, the Home
In android phones, the Home
screen is the Live tiles which are
screen has background wallpaper
the combination of some basic
Home with basic apps like camera,
apps like camera, gallery, phone,
Screen gallery, phone, contact, etc. The
message, contact etc. with
widgets can also add to the home
some other useful apps and
screen.
widgets.
In Android, the Kernel type is In Windows, the Kernel type is
Kernel
Linux-based. Hybrid with modules here.
Android is an open-source
platform, so it has more
applications and games than a Windows Store does not even
windows operating system. offer you millions of apps.
Apps Android OS comes with Google Moreover, some of these apps and
PlayStore, which has more than games are free to download, while
2.2 million applications and some are paid.
games that work with different
Android versions.
Windows apps are charged for the
Cost Android apps are free of cost.
original version.
The Windows operating system
offers you more security as
compared to Android OS.
Android is not more secured The Windows Store is not as
Security because it is an open-source simple as the Android Operating
platform. system.
To upload any apps, users need to
go through strict security
checkups.
Android OS uses Java, C, C++ Windows OS uses C, C++
Languages
languages. languages.
Supported Android OS supports ARM,
Windows OS only supports x86
platforms MIPS, x86, I.MX.
Root All Android OS are supported Currently, any Windows phone
Support for root access. OS does not support root access.
Android provides a clear set of In Windows Phone, a lot of
Settings settings for different applications settings make users confused, and
and makes user jobs much easier. users face difficulties.
Users can customize the Windows Phone is strict as the
keyboard layout depending on user has to go with a swipe
Keyboard
their use, whether it has to go for keyboard and leaves no other
a default version or a swipe one. choice for users.

Q9 Explain Need Of Android? 4M


Ans • There are so many reasons you should choose the Android platform for
mobile application development.
• Zero/negligible development cost
• The development tools like Android SDK, JDK, and Eclipse IDE, etc. are
free to download for the android mobile application development. Also,
Google charges a small fee of $25, to distribute your mobile app on the
Android Market.
• Open Source
• The Android OS is an open-source platform based on the Linux kernel and
multiple open-source libraries. In this way, developers are free to
contribute to or extend the platform as necessary for building mobile apps
which run on Android devices.
• Multi-Platform Support
• In the market, there is a wide range of hardware devices powered by the
Android OS, including many different phones and tablets. Even the
development of android mobile apps can occur on Windows, Mac OS, or
Linux.
• Multi-Carrier Support
• World wide a large number of telecom carriers like Airtel, Vodafone, Idea
Cellular, AT&T Mobility, BSNL, etc. are supporting Android-powered
phones.
• Open Distribution Model
• Android Market place (Google Play store) has very few restrictions on the
content or functionality of an android app. So the developer can distribute
their app through the Google Play store and as well other distribution
channels like Amazon’s app store.

Q10 . Write Down The Steps How To Install Android Studio? 4M


Ans
Step 1: Go to https://developer.android.com/android-studio/download to get the
Android Studio executable or zip file
Step 2:
● Click on the Download Android Studio Button.
● Click on the “I have read and agree with the above terms and conditions”
checkbox followed by the download button
● Click on the Save file button in the appeared prompt box and the file will start
downloading.
Step 3: After the downloading has finished, open the file from downloads and will
prompt the following dialog box. Click on next. In the next prompt, it’ll ask for a
path for installation. Choose a path and hit next.
Step 4: It will start the installation, and once it is completed, it will be like the
image shown below.
Step 5: Once “Finish” is clicked, it will ask whether the previous settings need to
be imported [if the android studio had been installed earlier], or not. It is better to
choose the ‘Don’t import Settings option’. Click the OK button.
Step 6: This will start the Android Studio. Meanwhile, it will be finding the
available SDK components.
Step 7: After it has found the SDK components, it will redirect to the Welcome
dialog box. Choose Standard and click on Next. Now choose the theme, whether
the Light theme or the Dark one. The light one is called the IntelliJ theme whereas
the dark theme is called Darcula. Choose as required. Click on the Next button.
Step 8: Now it is time to download the SDK components. Click on Finish.
Components begin to download let it complete. The Android Studio has been
successfully configured. Now it’s time to launch and build apps. Click on the
Finish button to launch it.
Step 9: Click on Start a new Android Studio project to build a new ap
Chapter 2 – INSTALLATION & CONFIGURATION OF
ANDROID
Q1. What Is OS? What Are OS Requirement For Android? 2M
Ans • An Operating System (OS) is an interface between a computer user and
computer hardware.
• An operating system is a software which performs all the basic tasks.
• Like file management, memory management, process management,
handling input and output, and controlling peripheral devices such as disk
drives and printers.
• Some examples include versions of Microsoft Windows (like Windows 10,
Windows 8, Windows 7, Windows Vista, and Windows XP),
• Apple's macOS (formerly OS X), Chrome OS, BlackBerry Tablet OS.
• Flavors of the open source operating system Linux.
• Some examples include Windows Server, Linux, and FreeBSD.
• Five of the most common operating systems are Microsoft Windows,
Apple macOS, Linux, Android and Apple's iOS.
• Microsoft Windows.
• Apple iOS.
• Google's Android OS.
• Apple macOS.
• Linux Operating SysteM
Android OS is a Linux-based mobile operating system that primarily runs on
smartphones and tablets. The Android platform includes an operating
system based upon the Linux kernel, a GUI, a web browser and end-user
applications that can be downloaded. Although the initial demonstrations of
Android featured a generic QWERTY smartphone and large VGA screen, the
operating system was written to run on relatively inexpensive handsets with
conventional numeric keypads.

Q2 What is Android Run time Envoirment 2,4


M
Ans Android Runtime (ART) is an application runtime environment used by the
Android operating system. Replacing Dalvik, the process virtual machine
originally used by Android, ART performs the translation of the application's
bytecode into native instructions that are later executed by the device's runtime
environment.

With a newer android version specifically from 4.4 version KitKat, there is the
concept of ART as an alternative to DVM. ART(Android Run Time) is a successor
of DVM which uses the same bytecode and .dex files (but not .odex files), with the
succession aiming at performance improvements transparent to the end-
users. Android 5.0 “Lollipop” is the first version in which ART is the only
included runtime. Now the thing that ART does is bring apps that are fully
compiled when they’re installed on the device. Therefore, higher performance as
no need to convert code to bytecode then compile. But the downside is you need
more storage space and a little longer to install because of compilation during
installation meaning it has to live on the device all the time. Hence, instead of
relatively small java code, we have larger bytecode/machine code. You may have
heard the terms odexed and de-odexed. What is done in this instance is you take a
small part of the application and then precompile it they can go ahead and make a
portion of their application optimized to run on their device, and so they’ve now
precompiled that section of the app and the rest of its compiled at runtime. So this
makes it just a little faster and more performant than in Dalvik. But this approach
takes a little more storage space.

Q3 Difference Btween DVM and ART


Ans DALVIK VIRTUAL MACHINE ANDROID RUN TIME
Faster Booting time Rebooting is significantly longer
The cache is built during the first
Cache builds up overtime
boot
Consumes a lot of storage space
Occupies less space due to JIT
internally due to AOT
Works best for Large storage
Works best for small storage devices
devices
Experimental and new – not much
Stable and tested virtual machine
app support comparatively
Extremely Faster and smoother
Faster and app loading time and
Longer app loading time
lower processor
usage
Uses JIT compiler(JIT: Just-In-Time) Uses AOT compiler(Ahead-Of-
Thereby resulting in lower storage space Time) thereby compiling apps
consumption when installed
Application lagging due to garbage collector Reduced application lagging and
pauses and JIT better user experience
App installation time is longer as
App installation time is comparatively lower
compilation is done during
as the compilation is performed later
installation
ART converts it just once at thetime

DVM converts bytecode every time you of app installation.


launch a specific app.
That makes CPU execution easier.
Improved battery life due to faster

execution.
It is slower than ART. It is faster.
It provides optimized battery
It does not provide optimized battery life as
performance as it consumes less
it consumes more power.
power.
While considering Booting, then this device
It lags in term of booting.
is fast.

Q4 What Is JDK? 2M
Ans JDK in Java is an abbreviation for Java Development Kit. It is a bundle of
software development tools and supporting libraries combined with the Java
Runtime Environment (JRE) and Java Virtual Machine (JVM).

Programmers familiar with Java might have the following common question.

To run Java Programs, just the Java Run-time Environment would be enough, but
why the complete JDK?

The answer is comparatively simple. Unlike typical Java programs, the real-time
Java applications require complex software toolkits and libraries available only in
JDK.

In the next segment, we will learn the architecture of JDK in Java.

The Architecture of JDK in Java

The architecture of JDK in Java includes the following modules as described in


the image below.
Q5 What Is SDK?
Ans Android SDK is a collection of libraries and Software Development tools that are
essential for Developing Android Applications. Whenever Google releases a new
version or update of Android Software, a corresponding SDK also releases with it.
In the updated or new version of SDK, some more features are included which are
not present in the previous version. Android SDK consists of some tools which are
very essential for the development of Android Application. These tools provide a
smooth flow of the development process from developing and debugging. Android
SDK is compatible with all operating systems such as Windows, Linux, macOS,
etc.
Q6 What Is Emulator? And Advantages and Disadvantages 2M
Ans
Emulator
The Android SDK provides a virtual mobile device emulator that runs on a
computer. An android emulator is used for executing, debugging, and testing
android applications. The emulator helps the developer to run a trial product
virtually without an actual hardware device. An emulator is similar to a physical
hardware mobile device including all the features that an actual mobile contains
except that it cannot place an actual phone call. The emulator comes with
predefined configurations for various Android phones, tablets, Wear OS, and
Android TV devices. Emulator represents a specific Android device that can be
used as a target platform to run and test your android application on your PC.

Advantages of Android Emulator

 Transfer of files is faster in virtual devices, as here a file can be transferred


through drag and drop.
 Emulator enables the programmer to work with physical sensors such as
accelerometers, gyroscopes, proximity, etc.
 One can play games, browse the internet, change settings, etc.
 Android emulator enables you to choose any version of your choice and
accordingly, a developer can build an app.
 Developer can check all possible test cases through android emulators.

Disadvantages of Android Emulator

 Android emulator works with slow speed as compared to actual physical


devices.
 Emulators cannot recognize the speed and performance of the battery,
location, and hardware-related activities.
 Testing on an emulator is not accurate as you are using a virtual device not
an actual device.
 One cannot identify issues related to networks or notifications on an
emulator.
 The emulator crashes at launch if it does not receive enough disk space.
Below is a sample image of how an Android Emulator looks like.

Q7 What Is AVD? 2M
Ans An Android Virtual Device (AVD) is a configuration that defines the
characteristics of an Android phone, tablet, Wear OS, Android TV, or Automotive
OS device that you want to simulate in the Android Emulator. The Device
Manager is a tool you can launch from Android Studio that helps you create and
manage AVDs.
• An Android Virtual Device (AVD) is a device configuration that is run
with the Android emulator.
• It works with the emulator to provide a virtual device-specific environment
in which to install and run Android apps.
• An Android emulator is an Android Virtual Device (AVD) that represents a
specific Android device.
• You can use an Android emulator as a target platform to run and test your
Android applications on your PC.
• It provides virtual device- specific Android Environment in which we can
install & test our Android Application.

Q8 Enlist System Requirement For Android Studio? 2M


 64-bit Microsoft® Windows® 8/10/11.
 x86_64 CPU architecture; 2nd generation Intel Core or newer, or AMD
CPU with support for a Windows Hypervisor.
 8 GB RAM or more.
 8 GB of available disk space minimum (IDE + Android SDK + Android
Emulator)
 1280 x 800 minimum screen resolution.

Q9 What Is ADT? 2M
Android Development Tools (ADT) is a plugin that is designed to give you a
powerful, integrated environment in which to build Android applications.

ADT allows you to quickly set up new Android projects, create an application UI,
add packages based on the Android Framework API, debug your applications
using the Android SDK tools, and even export signed (or unsigned) .apk files in
order to distribute your application.

Developing 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.
Q10 Compare JVM And DVM? 4M
JVM(Java Virtual Machine) DVM(Dalvik Virtual Machine)
Stack-based VM that performs Register-based VM that uses registers
arithmetic and logic operations through located
push and pop operands. The result of in the CPU to perform arithmetic and
operations is stored in stack memory. logic operations.
Source code files are first of all compiled
into Java bytecode format like JVM.
Java source code is compiled into Java
Further, the DEX compiler(dx tool)
bytecode format(.class file) that further
converts the Java bytecode into Dalvik
translates into machine code.
bytecode(classes.dex) file
that will be used to create the .apk file.
More information is required to the VM
for data loading and manipulation as Instruction size is larger as it needs to
well as method loading in the stack encode the source and destination register of the VM.
data structure.
Compiled bytecode size is compact
Compiled bytecode size is larger as each
because the location of the operand is
instruction needs all implicit operands.
implicitly on the operand stack.
The executable file for the device is .jar The executable file for the device is
file. .apk file.
A single instance of JVM is configured
The device runs multiple DVM instances
with shared processes and memory
with a separate process in shared memory space to
space in order to run all deployed
deploy the code of each application.
applications.
Supports multiple operating systems Support only the Android operation
like Linux, Windows, and Mac OS. system.

Q11 Explain DVM With Diagram? 4M


Ans Dalvik Virtual Machine is a Register-Based virtual machine. It was designed and
written by Dan Bornstein with contributions of other Google engineers as part of
the Android mobile phone platform. The Dalvik virtual machine was named after
Bornstein after the fishing village “Dalvík” in Eyjafjörður, Iceland, where some of
his ancestors used to live.

Working of DVM
The Java Compiler(javac) converts the Java Source Code into Java Byte-
Code(.class). Then DEX Compiler converts this (.class) file into in Dalvik Byte
Code i.e. “.dex” file.
Application

For Android, a new Virtual machine was developed by Google as stated above. It
uses registers of the CPU to store the operands. So no requirement of any pushing
and popping of instructions. Hence making execution faster. The instructions
operate on virtual registers, being those virtual registers memory positions in the
host device. Register-based models are good at optimizing and running on low
memory. They can store common sub-expression results which can be used again
in the future. This is not possible in a Stack-based model at all. Dalvik Virtual
Machine uses its own byte-code and runs “.dex”(Dalvik Executable File) file.

AdvantagesDVM
supports the Android operating system only.

 In DVM executable is APK.


 Execution is faster.
 From Android 2.2 SDK Dalvik has it’s own JIT (Just In Time) compiler.
 DVM has been designed so that a device can run multiple instances of the
Virtual Machine effectively.
 Applications are given their own instances.

Disadvantages

 DVM supports only Android Operating System.


 For DVM very few Re-Tools are available.
 Requires more instructions than register machines to implement the same
high-level code.
 App Installation takes more time due to dex.
 More internal storage is required.

Q12 Explain Android SDK and its tools


Ans
About Android SDK

Android SDK is a collection of libraries and Software Development tools that are
essential for Developing Android Applications. Whenever Google releases a new
version or update of Android Software, a corresponding SDK also releases with it.
In the updated or new version of SDK, some more features are included which are
not present in the previous version. Android SDK consists of some tools which are
very essential for the development of Android Application. These tools provide a
smooth flow of the development process from developing and debugging. Android
SDK is compatible with all operating systems such as Windows, Linux, macOS,
etc.

1. Android SDK Tools

Android SDK tool is an important component of Android SDK. It consists of a


complete set of development and debugging tools. Below are the SDK developer
tools:

 Android SDK Build tool.


 Android Emulator.
 Android SDK Platform-tools.
 Android SDK Tools.

1.Android SDK Build-Tools

Android SDK build tools are used for building actual binaries of Android App.
The main functions of Android SDK Build tools are built, debug, run and test
Android applications. The latest version of the Android SDK Build tool is 30.0.3.
While downloading or updating Android in our System, one must ensure that its
latest version is download in SDK Components.

2. Android Emulator
An Android Emulator is a device that simulates an Android device on your
system. Suppose we want to run our android application that we code. One option
is that we will run this on our Android Mobile by Enabling USB Debugging on
our mobile. Another option is using Android Emulator. In Android Emulator the
virtual android device is shown on our system on which we run the Android
application that we code.

Thus, it simply means that without needing any physical device Android SDK
component “Android Emulator” provides a virtual device on the System where we
run our Application. The emulator’s come with the configuration for Various
android phones, tablets, Wear OS, and Android TV devices

3. Android SDK Platform-tools

Android SDK Platform-tools is helpful when we are working on Project and they
will show the error messages at the same time. It is specifically used for testing. It
includes:

 Android Debug Bridge (ADB), is a command-line tool that helps to


communicate with the device. It allows us to perform an action such as
Installing App and Debugging App etc.
 Fastboot allows you to flash a device with a new system image.
 Systrace tools help to collect and inspect timing information. It is very
crucial for App Debugging.

4. Android SDK Tools

Android SDK tool is a component of SDK tool. It consists of a set of tools which
and other Utilities which are crucial for the development of Android Application.
It contains the complete set of Debugging and Development tools for android.

Q13 Write Down Steps How To Create AVD In Android Studio? 4M


Ans 1. Open the Device Manager.
2. Click Create Device. The Select Hardware window appears. ...
3. Select a hardware profile, then click Next. ...
4. Select the system image for a particular API level, and then click Next.
5. Change the AVD properties as needed, and then click Finish.
3. UI components and Layouts
Q1 List layouts in android UI design 2M
Sr.No Layout & Description
Linear Layout
1 LinearLayout is a view group that aligns all children in a single direction,
vertically or horizontally.
Relative Layout
2 RelativeLayout is a view group that displays child views in relative
positions.
Table Layout
3
TableLayout is a view that groups views into rows and columns.
Absolute Layout
4
AbsoluteLayout enables you to specify the exact location of its children.
Frame Layout
5 The FrameLayout is a placeholder on screen that you can use to display a
single view.
List View
6
ListView is a view group that displays a list of scrollable items.
Grid View
7 GridView is a ViewGroup that displays items in a two-dimensional,
scrollable grid.

Q2 List different attributes of linear layout. 2M

Ans android:orientation=”vertical”
android:orientation=”horizantal”
Is the most basic layout in android studio, that aligns all the children sequentially
either in a horizontal manner or a vertical manner by specifying the
android:orientation attribute. If one applies android:orientation=”vertical” then
elements will be arranged one after another in a vertical manner and If you apply
android:orientation=”horizontal” then elements will be arranged one after another
in a horizontal manner.

Q3 List different attributes of Absolute layout. 2M


Ans android:id :- This is the ID which uniquely identifies the layout.

android:layout_x :- This specifies the x-coordinate of the view.

android:layout_y:- This specifies the y-coordinate of the view.

Q4 List different attributes of Frame layout. 2M


Ans android:foreground

This defines the drawable to draw over the content and possible values may be a
color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

android:foregroundGravity

Defines the gravity to apply to the foreground drawable. The gravity defaults to
fill. Possible values are top, bottom, left, right, center, center_vertical,
center_horizontal etc.

android:measureAllChildren

Determines whether to measure all children or just those in the VISIBLE or


INVISIBLE state when measuring. Defaults to false.

Q5 List different attributes of Table layout. 2M


android:id :- This is the ID which uniquely identifies the layout.

android:collapseColumns

This specifies the zero-based index of the columns to collapse. The column indices
must be separated by a comma: 1, 2, 5.

android:shrinkColumns

The zero-based index of the columns to shrink. The column indices must be
separated by a comma: 1, 2, 5.

android:stretchColumns

The zero-based index of the columns to stretch. The column indices must be
separated by a comma: 1, 2, 5.

Q6 List important files and folders in android directory structure. 2M


The android project contains different types of app modules, source code files, and
resource files. We will explore all the folders and files in the android app.

1. Manifests Folder
2. Java Folder
3. res (Resources) Folder
o Drawable Folder
o Layout Folder
o Mipmap Folder
o Values Folder
4. Gradle Scripts

Q7 List Components of an Android Application. 2M

1. Activities
2. Service
3. Content Providers
4. Broadcast Receiver
5.Widgets
6. View

Q8 What is use of AndroidManifest.xml file in any android application 4M


Every project in Android includes a Manifest XML file, which is
AndroidManifest.xml, located in the root directory of its project hierarchy. The
manifest file is an important part of our app because it defines the structure and
metadata of our application, its components, and its requirements. This file
includes nodes for each of the Activities, Services, Content Providers, and
Broadcast Receivers that make the application, and using Intent Filters and
Permissions determines how they coordinate with each other and other
applications.

The manifest file also specifies the application metadata, which includes its icon,
version number, themes, etc., and additional top-level nodes can specify any
required permissions, and unit tests, and define hardware, screen, or platform
requirements. The manifest comprises a root manifest tag with a package attribute
set to the project’s package. It should also include an xmls:android attribute that
will supply several system attributes used within the file. We use the versionCode
attribute is used to define the current application version in the form of an integer
that increments itself with the iteration of the version due to update. Also, the
versionName attribute is used to specify a public version that will be displayed to
the users.

A manifest file includes the nodes that define the application components, security
settings, test classes, and requirements that make up the application. Some of the
manifest sub-node tags that are mainly used are:

The main component of the AndroidManifest.xml file is known as manifest.


Additionally, the packaging field describes the activity class’s package name. It
must contain an <application> element with the xmlns:android and package
attribute specified.
Q9 Explain directory structure in android application in detail. 4M
 src - Java source files associated with your project. This includes the
Activity "controller" files as well as your models and helpers.
 res - Resource files associated with your project. All graphics, strings,
layouts, and other resource files are stored in the resource file hierarchy
under the res directory.
 res/layout - XML layout files that describe the views and layouts for each
activity and for partial views such as list items.
 res/values - XML files which store various attribute values. These include
strings.xml, dimens.xml, styles.xml, colors.xml, themes.xml, and so on.
 res/drawable - Here we store the various density-independent graphic
assets used in our application.
 res/drawable-hdpi - Series of folders for density specific images to use
for various resolutions.
 res/mipmap - most commonly used for application icons. See this section
for more details.

The most frequently edited files are:

 res/layout/activity_foo.xml - This file describes the layout of the activity's


UI. This means the placement of every view object on one app screen.
 src/.../FooActivity.java - The Activity "controller" that constructs the
activity using the view, and handles all event handling and view logic for
one app screen.
 AndroidManifest.xml - This is the Android application definition file. It
contains information about the Android application such as minimum
Android version, permission to access Android device capabilities such as
internet access permission, ability to use phone permission, etc.

Other less edited folders include:

 gen - Generated Java code files, this library is for Android internal use
only.
 assets - Uncompiled source files associated with your project; Rarely used.
 bin - Resulting application package files associated with your project once
it’s been built.
 libs - Before the introduction of Gradle build system, this directory was
used for any secondary libraries (jars) you might want to link to your app.

Q10 Explain following files. I. Main activity file II. Manifest file III. String file 4M
IV. Layout file
I.activity_main
The activity_main.xml is a layout file available in res/layout directory, that is
referenced by your application when building its interface. You will modify this
file very frequently to change the layout of your application.
II. Manifest file
A manifest is a XML file that contains settings that informs Windows how to
handle a program when it is started. The manifest can be embedded inside the
program file (as a resource) or it can be located in a separate external XML file.
III. String file
String.xml file contains all the strings which will be used frequently in Android
project. String.xml file present in the values folder which is sub folder of res folder
in project structure.In Android Studio, we have many Views such as
TextView,Button,EditText,CheckBox,RadioButton etc. These views have a
common attribute named text. we can assign value to this attribute directly or via
string.xml.
IV. Layout file
A file layout is a definition that represents the data structure of a flat (text) file to
be processed. When reading from or writing to a flat file, PeopleCode can use a
file layout as a template to identify and correctly process the records and fields of
the file.
In the Project window, click the module you want to add a layout to. In the main
menu, select File > New > XML > Layout XML File. In the dialog that appears,
provide the filename, the root layout tag, and the source set where the layout
belongs.

Q11 What are view and viewgroup classes in android? Why layouts are created 4M
using xml file?

Q12 Define a) View b) View group c) Layout 4M


Ans
View
The View class is the base class or we can say that it is the superclass for all the
GUI components in android. For example, the EditText class is used to accept the
input from users in android apps, which is a subclass of View, and another
example of the TextView class which is used to display text labels in Android apps
is also a subclass of View.

ViewGroup

The ViewGroup class is a subclass of the View class. And also it will act as a base
class for layouts and layouts parameters. The ViewGroup will provide an
invisible container to hold other Views or ViewGroups and to define the layout
properties. For example, Linear Layout is the ViewGroup that contains UI controls
like Button, TextView, etc., and other layouts also. ViewGroup Refer to the
android.view.ViewGroup class, which is the base class of some special UI classes
that can contain other View objects as children. Since ViewGroup objects are also
View objects, multiple ViewGroup objects and View objects can be organized into
an object tree to build a complex UI structure.

Layout

Android Layout is used to define the user interface that holds the UI controls or
widgets that will appear on the screen of an android application or activity screen.
Generally, every application is a combination of View and ViewGroup.

Q13 Difference between View and Viewgroup 4M

View ViewGroup
View is a simple rectangle box that ViewGroup is the invisible container. It
responds to the user’s actions. holds View and ViewGroup
View is the SuperClass of All ViewGroup is a collection of Views
component like TextView, EditText, (TextView, EditText, ListView, etc..),
ListView, etc somewhat like a container.
A View object is a component of the
A ViewGroup object is a layout, that is,
user interface (UI) like a button or a
a container of other ViewGroup objects
text box, and it’s also called a
(layouts) and View objects (widgets)
widget.
For example, LinearLayout is the
Examples are EditText, Button,
ViewGroup that contains Button(View),
CheckBox, etc.
and other Layouts also.
View refers to the ViewGroup refers to the android.view.
android.view.View class ViewGroup class
android.view.View which is the
ViewGroup is the base class for Layouts.
base class of all UI classes.

Q14 Explain Types of Layout in android 4M

Types of Android Layout

 Android Linear Layout: LinearLayout is a ViewGroup subclass, used to


provide child View elements one by one either in a particular direction
either horizontally or vertically based on the orientation property.
 Android Relative Layout: RelativeLayout is a ViewGroup subclass, used
to specify the position of child View elements relative to each other like (A
to the right of B) or relative to the parent (fix to the top of the parent).
 Android Constraint Layout: ConstraintLayout is a ViewGroup subclass,
used to specify the position of layout constraints for every child View
relative to other views present. A ConstraintLayout is similar to a
RelativeLayout, but having more power.
 Android Frame Layout: FrameLayout is a ViewGroup subclass, used to
specify the position of View elements it contains on the top of each other to
display only a single View inside the FrameLayout.
 Android Table Layout: TableLayout is a ViewGroup subclass, used to
display the child View elements in rows and columns.
 Android Web View: WebView is a browser that is used to display the web
pages in our activity layout.
 Android ListView: ListView is a ViewGroup, used to display scrollable
lists of items in a single column.
 Android Grid View: GridView is a ViewGroup that is used to display a
scrollable list of items in a grid view of rows and columns.

Q15 Explain Components of an Android Application. 4M


1)Activities

An activity represents a single screen with a user interface,in-short Activity


performs actions on the screen. For example, an email application might have one
activity that shows a list of new emails, another activity to compose an email, and
another activity for reading emails. If an application has more than one activity,
then one of them should be marked as the activity that is presented when the
application is launched.

An activity is implemented as a subclass of Activity class as follows –

public class MainActivity extends Activity {}

2)Services

A service is a component that runs in the background to perform long-running


operations. For example, a service might play music in the background while the
user is in a different application, or it might fetch data over the network without
blocking user interaction with an activity.A service is implemented as a subclass
of Service class as follows –

public class MyService extends Service {}

3) Broadcast Receivers

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.A broadcast
receiver is implemented as a subclass of BroadcastReceiver class and each
message is broadcaster as an Intent object.

public class MyReceiver extends BroadcastReceiver {

public void onReceive(context,intent){}}

4)Content Providers

A content provider component supplies data from one application to others on


request. Such requests are handled by the methods of the ContentResolver class.
The data may be stored in the file system, the database or somewhere else entirely.

A content provider is implemented as a subclass of ContentProvider class and


must implement a standard set of APIs that enable other applications to perform
transactions.

public class MyContentProvider extends ContentProvider {

public void onCreate()}


Q16 List and Explain the Resource files 4M
color/

XML files that define a state list of colors. They are saved in res/color/ and
accessed from the R.color class.

drawable/

Image files like .png, .jpg, .gif or XML files that are compiled into bitmaps, state
lists, shapes, animation drawable. They are saved in res/drawable/ and accessed
from the R.drawable class.

layout/

XML files that define a user interface layout. They are saved in res/layout/ and
accessed from the R.layout class.

menu/

XML files that define application menus, such as an Options Menu, Context
Menu, or Sub Menu. They are saved in res/menu/ and accessed from the R.menu
class.

raw/Arbitrary files to save in their raw form. You need to call


Resources.openRawResource() with the resource ID, which is R.raw.filename to
open such raw files.
values/

XML files that contain simple values, such as strings, integers, and colors. For
example, here are some filename conventions for resources you can create in this
directory −

 arrays.xml for resource arrays, and accessed from the R.array class.
 integers.xml for resource integers, and accessed from the R.integer class.
 bools.xml for resource boolean, and accessed from the R.bool class.
 colors.xml for color values, and accessed from the R.color class.
 dimens.xml for dimension values, and accessed from the R.dimen class.
 strings.xml for string values, and accessed from the R.string class.
 styles.xml for styles, and accessed from the R.style class.
4. Designing User interface with View
Q1 List view classes in android application development 2M
TextView.
EditText.
Button.
ImageView.
ImageButton.
CheckBox.
RadioButton
.Grid View
Scroll View
ListView.
Q2 Explain attributes wrap_content and match_parent with respect to 2M
viewgroups.

Q3 What is Toast in Android? 2M


A Toast is a feedback message. It takes a very little space for displaying while the
overall activity is interactive and visible to the user. It disappears after a few
seconds. It disappears automatically. If the user wants a permanently visible
message, a Notification can be used. Another type of Toast is custom Toast, in
which images can be used instead of a simple message.
Syntyax
Toast t = Toast.makeText(getApplicationContext(), "This a positioned toast
message", Toast.LENGTH_LONG);
t.setGravity(Gravity.BOTTOM | Gravity.RIGHT, 0, 0);
t.show();

Q4 Enlist elements in UI. 2M


When designing your interface, try to be consistent and predictable in your choice
of interface elements. Whether they are aware of it or not, users have become
familiar with elements acting in a certain way, so choosing to adopt those elements
when appropriate will help with task completion, efficiency, and satisfaction.

Interface elements include but are not limited to:

 Input Controls: checkboxes, radio buttons, dropdown lists, list boxes,


buttons, toggles, text fields, date field
 Navigational Components: breadcrumb, slider, search field, pagination,
slider, tags, icons
 Informational Components: tooltips, icons, progress bar, notifications,
message boxes, modal windows
 Containers: accordion

Q5 What is TextView & EditText? Explain TextView attributes. 4M


Textview
A TextView displays text to the user and optionally allows them to edit it. A
TextView is a complete text editor, however the basic class is configured to not
allow editing.
android:phoneNumber :- If set, specifies that this TextView has a phone number input
method. Possible value either "true" or "false".
android:text :- Text to display.
android:textAllCaps :- Present the text in ALL CAPS. Possible value either "true" or "false".
android:textColor :- Text color. May be a color value, in the form of "#rgb", "#argb",
"#rrggbb", or "#aarrggbb".
android:textColorHighlight :- Color of the text selection highlight.
android:textColorHint : -Color of the hint text. May be a color value, in the form of "#rgb",
"#argb", "#rrggbb", or "#aarrggbb".
android:textIsSelectable :- Indicates that the content of a non-editable text can be selected.
Possible value either "true" or "false".
android:textSize :- Size of the text. Recommended dimension type for text is "sp" for scaled-
pixels (example: sp).
android:textStyle :- Style (bold, italic, bolditalic) for the text. You can use or more of the
following values separated by '|'.

 normal - 0
 bold - 1
 italic - 2

Q6 What is ScrollView? Explain how to create ScrollView with a TextView and 4M


with a LinearLayout.
In Android, a ScrollView is a view group that is used to make vertically scrollable
views. A scroll view contains a single direct child only. In order to place multiple
views in the scroll view, one needs to make a view group(like LinearLayout) as a
direct child and then we can define many views inside it. A ScrollView supports
Vertical scrolling only, so in order to create a horizontally scrollable view,
HorizontalScrollView is used.

Create

Step 1: Create a new project and name it LinearLayoutInsideScrollView.

Step 2: Open res -> layout ->activity_main.xml (or) main.xml and add following
code:

In this step we open xml file and then create custom layout for user registration
form using different views(TextView, EditText or any other view). After creating
different views we enclose them inside Linear Layout and then we enclose the
whole layout in ScrollView to make all the element or views scrollable. In this
registration form we display different fields with one Button named “Submit” to
submit the data of the user.

Step 3: Open src -> package -> MainActivity.java

In this step Firstly we get the reference of different views(TextView, EditText or


any other view) that are used in xml file. After that we perform click event on the
Button so Whenever a user clicks on Submit Button, we check all the fields are
filled or not if filled we display a Successful message by using a toast else we
display an error message at that particular field.

<LinearLayout 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"
android:background="@color/whiteColor"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<!-- vertical ScrollView to make all the items or views scrollable -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none">

<!-- LinearLayout Inside ScrollView -->

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginRight="10dp"
android:layout_weight="0.6"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="Last Name"
android:textColor="@color/blackColor" />
</LinearLayout>
</ScrollView>

Q7 Develop an android application using Date & Time Picker( Refer Program 4M
notes)

Q8 . Demonstrate use of List View & Grid View. 4M


• Android GridView shows items in two-dimensional scrolling grid (rows &
columns) and the grid items are not necessarily predetermined but they
automatically inserted to the layout using a ListAdapter
• Grid view
• An adapter actually bridges between UI components and the data source
that fill data into UI Component. Adapter can be used to supply the data to
like spinner, list view, grid view etc.
• The ListView and GridView are subclasses of AdapterView and they can
be populated by binding them to an Adapter, which retrieves data from an
external source and creates a View that represents each data entry. OR
• A GridView is a type of AdapterView that displays items in a two-
dimensional scrolling grid. Items are inserted into this grid layout from a
database or from an array. The adapter is used for displaying this data,
setAdapter() method is used to join the adapter with GridView. The main
function of the adapter in GridView is to fetch data from a database or
array and insert each piece of data in an appropriate item that will be
displayed in GridView.
Attributes
• android:columnWidth
This specifies the fixed width for each column. This could be in px, dp, sp, in, or
mm.
• android:gravity
Specifies the gravity within each cell. Possible values are top, bottom, left, right,
center, center_vertical, center_horizontal etc.
• android:horizontalSpacing
Defines the default horizontal spacing between columns. This could be in px, dp,
sp, in, or mm.
• android:stretchMode
Defines how columns should stretch to fill the available empty space, if any. This
must be either of the values −
none − Stretching is disabled.
spacingWidth − The spacing between each column is stretched.
columnWidth − Each column is stretched equally.
spacingWidthUniform − The spacing between each column is uniformly
stretched..
• android:verticalSpacing
Defines the default vertical spacing between rows. This could be in px, dp, sp, in,
or mm.
Listview
• Android ListView is a view which groups several items and display them
in vertical scrollable list. The list items are automatically inserted to the list
using an Adapter that pulls content from a source such as an array or
database.
Listview Attributes are used
• android:id :-This is the ID which uniquely identifies the layout.
• android:divider :-This is drawable or color to draw between list items.
• android:dividerHeight :-This specifies height of the divider. This could
be in px, dp, sp, in, or mm.
• android:entries :-Specifies the reference to an array resource of ListView.
• android:footerDividersEnabled :-When set to false, the ListView will not
draw the divider before each footer view. The default value is true.
• android:headerDividersEnabled :-When set to false, the ListView will
not draw the divider after each header view. The default value is true.

Q9 Describe with example Checkbox & Radiobutton. 4M


Radio button
- In Android, RadioButton are mainly used together in a RadioGroup. In
RadioGroup checking the one radio button out of several radio button added in it
will automatically unchecked all the others. It means at one time we can checked
only one radio button from a group of radio buttons which belong to same radio
group. The most common use of radio button is in Quiz Android App code.
-RadioButon is a two state button that can be checked or unchecked. If a radio
button is unchecked then a user can check it by simply clicking on it. Once a
RadiaButton is checked by user it can’t be unchecked by simply pressing on the
same button. It will automatically unchecked when you press any other
RadioButton within same RadioGroup.
Example
<LinearLayout 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"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#e0e0e0"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select your favourite wwe SuperStar :: "
android:textColor="#000"
android:textSize="20sp"
android:textStyle="bold" />

<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<RadioButton
android:id="@+id/romanReigns"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:checked="false"
android:text="@string/romanReigns"
android:textColor="#154"
android:textSize="20sp"
android:textStyle="bold" />

<RadioButton
android:id="@+id/goldBerg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:checked="false"
android:text="@string/goldBerg"
android:textColor="#154"
android:textSize="20sp"
android:textStyle="bold" />

</RadioGroup>

<Button
android:id="@+id/submitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="20dp"
android:background="#0f0"
android:padding="10dp"
android:text="Submit"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>

</LinearLayout>
Java File
package example.gb.radiobuttonexample;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

goldBerg, romanReigns;
String selectedSuperStar;
Button submit;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
goldBerg = (RadioButton) findViewById(R.id.goldBerg);
romanReigns = (RadioButton) findViewById(R.id.romanReigns);

submit = (Button) findViewById(R.id.submitButton);


submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){

if (romanReigns.isChecked()) {
selectedSuperStar = romanReigns.getText().toString();
} else (goldBerg.isChecked()) {
selectedSuperStar = goldBerg.getText().toString();
}
Toast.makeText(getApplicationContext(), selectedSuperStar,
Toast.LENGTH_LONG).show(); // print the value of selected super star}});}}
Unit 5: Activity & Multimedia with Database (20 )
Q1 Write the syntax for Intent-Filter tag 2M
Ans An intent filter declares the capabilities of its parent component — what an
activity or service can do and what types of broadcasts a receiver can handle. It
opens the component to receiving intents of the advertised type, while filtering out
those that are not meaningful for the component.

intent-filter android:icon="drawable resource"


android:label="string resource"
android:priority="integer" >
...
</intent-filter>

Q2 What is Service in android? Enlist its Types. 2M


Service
Services in Android are a special component that facilitates an application to run
in the background in order to perform long-running operation tasks. The prime aim
of a service is to ensure that the application remains active in the background so
that the user can operate multiple applications at the same time. A user-interface is
not desirable for android services as it is designed to operate long-running
processes without any user intervention. A service can run continuously in the
background even if the application is closed or the user switches to another
application.
Types Of service

1. Foreground Services
2. 2. Background Services:
3. 3. Bound Services:
Q3 Enlist different ways to handle databases in android? Elaborate any one 2M
Ans There are many ways to store your data, such as in an online database, in a local
SQLite database, or even in a text file.
SQLite: It is a opensource SQL database that stores data to a text file on a device.
Android comes in with built in SQLite database implementation. SQLite supports
all the relational database features. In order to access this database, you don't need
to establish any kind of connections for it like JDBC,ODBC e.t.

Q4 What Is Activity in android? 2M


Ans What Is Activity in android? An Android activity is one screen of the Android
app's user interface. In that way an Android activity is very similar to windows in
a desktop application.An Android app may contain one or more activities,
meaning one or more screens.
Q5 What is an Intent? Enlist its Types. 2M
Ans
Intent is to perform an action. It is mostly used to start activity, send
broadcast receiver, start services and send message between two activities.
There are two intents available in android as Implicit Intents and Explicit
IntentsThere are two types of intents in android

1. Explicit intents specify which application will satisfy the intent, by supplying
either the target app's package name or a fully-qualified component class
name. You'll typically use an explicit intent to start a component in your own
app, because you know the class name of the activity or service you want to
start. For example, you might start a new activity within your app in response
to a user action, or start a service to download a file in the background.
2. Implicit intents do not name a specific component, but instead declare a
general action to perform, which allows a component from another app to
handle it. For example, if you want to show the user a location on a map, you
can use an implicit intent to request that another capable app show a specified
location on a map.

Q6 What Is Sensor in android? Enlist its Types. 2M


Ans Sensors can be used to monitor the three-dimensional device movement i.e.
motion, orientation or change in the environment of the device. These sensors are
capable of providing raw data with high precision and accuracy, and are useful if
you want to monitor three-dimensional device movement or positioning, or you
want to monitor changes in the ambient environment near a device. The Android
platform supports three broad categories of sensors.
1) Motion Sensors : These are used to measure acceleration forces and rotational
forces along with three axes.
2) Position Sensors: These are used to measure the physical position of device.
3) Environmental Sensors: These are used to measure the environmental changes
such as temperature, humidity etc
Q7 What is Animation? Enlist its Types 2M
Ans Animations can add visual cues that notify users about what's going on in your
app. They are especially useful when the UI changes state, such as when new
content loads or new actions become available. Animations also add a polished
look to your app, which gives it a higher quality look and feel.
There’s three main types of animations available on Android: ViewAnimation,
Property Animation, DrawableAnimation and much more.
Q8 What is TTS feature of Android? 2M
Ans Text to speech (TTS) makes an android device read the text and convert it to audio
out via the speaker. Android TTS supports multiple languages. TTS is a simple but
powerful feature. It can also be effectively used in mobile APPs dedicated to
visually impaired people or in educational app for kids or can be used in
pronunciation learning app, etc. These are some of the ways you can use TTS.
Using TextToSpeech enhances interaction between the user and the mobile
application.
Q9 Define content provider and explain fragments. (CO5) 4M
Ans  Content Provider
A Content Provider component supplies data from one application to others on
request. Such requests are handled by the methods of the ContentResolver class. A
content provider can use different ways to store its data and the data can be stored
in files, in a database or even over a network. Content Providers support the four
basic operations, normally called CRUDoperations. CRUD is the acronym for
create, read, update and delete.
A content provider manages access to a central repository of data. A provider is
part of an Android application, which often provides its own UI for working with
the data. However, content providers are primarily intended to be used by other
applications, which access the provider using a provider client object. Together,
providers and provider clients offer a consistent, standard interface to data that
also handles inter-process communication and secure data access.
 Fragmention
A fragment is an independent Android component which can be used by an
activity. A fragment encapsulates functionality so that it is easier to reuse within
activities and layouts. A fragment runs in the context of an activity, but has its own
life cycle and typically its own user interface. It is also possible to define
fragments without an user interface, i.e., headless fragments
Q10 Explain the activity life cycle. 4M

activity life cycle.


Android Activity Lifecycle is controlled by 7 methods of android.app.Activity
class. The android Activity is the subclass of ContextThemeWrapper class. 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.

onCreate :- called when activity is first created


onStart called when activity is becoming visible to the user.

onResume called when activity will start interacting with the user.

onPause called when activity is not visible to the user.


onStop called when activity is no longer visible to the user.

onRestart called after your activity is stopped, prior to start.

onDestroy called before the activity is destroyed.


Q11 Draw Android System Architecture? (Means Android Architecture) refer 4M
Unit No 1

Q12 Explain with Diagram Service Life Cycle? 4M


Ans There can be two forms of a service. The lifecycle of service can follow two
different paths: started or bound.
1) Started Service A service is started when component (like activity) calls
startService() method, now it runs in the background indefinitely. It is stopped by
stopService() method. The service can stop itself by calling the stopSelf() method.
2) Bound Service A service is bound when another component (e.g. client) calls
bindService() method. The client can unbind the service by calling the
unbindService() method. The service cannot be stopped until all clients unbind the
service

Like any other components service also has callback methods. These will be
invoked while the service is running to inform the application of its state.
onCreate() This is the first callback which will be invoked when any component
starts the service. If the same service is called again while it is still running this
method wont be invoked. Ideally one time setup and intializing should be done in
this callback. onStartCommand() This callback is invoked when service is started
by any component by calling startService(). It basically indicates that the service
has started and can now run indefinetly.
onBind() This is invoked when any component starts the service by calling
onBind.

onUnbind() This is invoked when all the clients are disconnected from the
service.

onRebind() This is invoked when new clients are connected to the service. It is
called after onUnbind
onDestroy() This is a final clean up call from the system. This is invoked just
before the service is being destroyed. Could be very useful to cleanup any
resources such as threads, registered listeners, or receivers
Q13 What is Fragment? Explain with example. 4M
Fragment is a part of an activity which enables more modular activity design. It
will not be wrong if we say a fragment is a kind of sub-activity. It represents
behaviour or a portion of user interface in an Activity.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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="fill_parent"
android:layout_height="fill_parent"
tools:context="example.javatpoint.com.fragmentexample.MainActivity">

<fragment
android:id="@+id/fragment1"
android:name="example.javatpoint.com.fragmentexample.Fragment1"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1"
/>

<fragment
android:id="@+id/fragment2"
android:name="example.javatpoint.com.fragmentexample.Fragment2"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1"
/>
</LinearLayout>
Q14 How to play Audio & Video in Android? 4M
To play Audio & Video in Android the multimedia framework is used. The
Android multimedia framework includes support for playing variety of common
media types, so that you can easily integrate audio, video and images into your
applications. You can play audio or video from media files stored in your
application's resources (raw resources), from standalone files in the file system, or
from a data stream arriving over a network connection, all using MediaPlayer
APIs.
The following classes are used to play sound and video in the Android framework:
MediaPlayer This class is the primary API for playing sound and video. An object
of this class can fetch, decode, and play both audio and video with minimal setup.
It supports several different media sources such as
 Internal URIs, such as one you might obtain from a Content Resolver
 Local resources
 External URLs (streaming)

AudioManager This class manages audio sources and audio output on a device.

For example,
Uri myUri = ....; // initialize Uri here
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(getApplicationContext(),myUri);
mediaPlayer.prepare();
mediaPlayer.start();
Q15 Explain how to Create & Connect SQLite? 4M
To create a database you just need to call this method openOrCreateDatabase with
your database name and mode as a parameter. It returns an instance of SQLite
database which you have to receive in your own object.Its syntax is given below

SQLiteDatabase db; db=openOrCreateDatabase(String path, int mode,


SQLiteDatabase.CursorFactory factory)

This method is used to create/open database. As the name suggests, it will open a
database connection if it is already there, otherwise, it will create a new one.
Arguments:
String path: Name of the database
Int mode: operating mode. Use 0 or "MODE_PRIVATE" for the default
operation, or "CREATE_IF_NECESSARY" if you like to give an option that "if a
database is not there, create it"
CursorFactory factory: An optional factory class that is called to instantiate a
cursor when a query is called Example,
db=openOrCreateDatabase("XYZ_Database",SQLiteDatabase.CREATE_IF_NEC
ESSARY,null)
Q16 What is Transaction? Explain with example. 4M
Transactions are units or sequences of work accomplished in a logical order,
whether in a manual fashion by a user or automatically by some sort of a database
program.
A transaction is the propagation of one or more changes to the database. For
example, if you are creating, updating, or deleting a record from the table, then
you are performing transaction on the table. It is important to control transactions
to ensure data integrity and to handle database errors , For Example
, BEGIN TRANSACTION;
UPDATE accounts
SET balance = balance - 1000
WHERE account_no = 100;

UPDATE accounts
SET balance = balance + 1000
WHERE account_no = 200;

INSERT INTO account_changes(account_no,flag,amount,changed_at)


VALUES(100,'-',1000,datetime('now'));

INSERT INTO account_changes(account_no,flag,amount,changed_at)


VALUES(200,'+',1000,datetime('now')); COMMIT;
Unit 6: Security & Application Deployment (20
Marks)
Q1 Describe location based services. List important methods 2M
Ans Location Based Services are provided by Android through its location framework.
The framework provides a location API which consists of certain classes and
interface. These classes and interface are the key components which allow us to
develop Location Based Application in Android
Classes and Interfaces of Location Based Services
LocationManager – This class helps to get access to the location service of the
system. LocationListener – This interface acts as the listener which receives
notification from the location manager when the location changes or the location
provider is disabled or enabled.
Location – This is the class which represents the geographic location returned at a
particular time.
Methods:
1 abstract void onConnected(Bundle connectionHint) This callback method is
called when location service is connected to the location client successfully. You
will use connect() method to connect to the location client.
2 abstract void onDisconnected() This callback method is called when the client
is disconnected. You will use disconnect() method to disconnect from the location
client.
3 abstract void onConnectionFailed(ConnectionResult result) This callback
method is called when there was an error connecting the client to the service.
4 abstract void onLocationChanged(Location location) This callback method
is used for receiving notifications from the LocationClient when the location has
change
Q3 Explain Geocoding & Reverse Geocoding. (CO6)
Ans Geocoding is the process of converting addresses (like a street address) into
geographic coordinates (like latitude and longitude), which you can use to place
markers on a map, or position the map.
A class for handling geocoding and reverse geocoding. Geocoding is the process
of transforming a street address or other description of a location into a (latitude,
longitude) coordinate. Reverse geocoding is the process of transforming a
(latitude, longitude) coordinate into a (partial) address. The amount of detail in a
reverse geocoded location description may vary, for example one might contain
the full street address of the closest building, while another might contain only a
city name and postal code. The Geocoder class requires a backend service that is
not included in the core android framework. The Geocoder query methods will
return an empty list if there no backend service in the platform. Use the isPresent()
method to determine whether a Geocoder implementation exists.
Reverse geocoding is the process of converting geographic coordinates into a
humanreadable address.
Reverse-Geocoding is a process used to convert coordinates (latitude and
longitude) to human-readable addresses. This is not exactly the opposite of
Geocoding. In Geocoding, the Place is associated with a name and fixed
coordinates. These coordinates are Double in nature. Negligible change in these
coordinates may still refer to the same place, but we shall never get the place name
as it is associated with only those fixed coordinates.

Q4 Enlist the steps to publish the Android application (means Deploy Apk) 2M
Ans Enlist the steps to publish the Android application.

Step 1: Sign up. Sign up for an account on the Android Developer Console. ...

Step 2: Create a new application. ...

Step 3: Prepare multimedia. ...

Step 4: Prepare code for release. ...

Step 5: Build a release-ready APK. ...

Step 6: Upload APK. ... Complete the checklist on the left until all the items have
a green checkmark

Q5 Name any 4 methods to get location data in android. 2M


Ans
1. float getAccuracy(): It gives us the accuracy of our location in metres.
3. double getAltitude():- It gives us the altitude of our place above sea level.

4. double getLatitude()

It gives the latitude coordinate of our place in degrees.

5. double getLongitude()

It gives the latitude coordinate of our place in degrees.

6. float getSpeed()

It gives the speed of our location change.

7. void setAccuracy(float accuracy)

Using setAccuracy(), you can set your custom accuracy in metres.

8. void setAltitude(double altitude)

Using setAltitude(), you can set the altitude of your place from sea level in metres.

9. void setBearing(float bearing)

Using the setBearing() method, you can set location bearing in degrees.

10. void setLatitude(double Latitude)

You can even set your location to some other latitude using the setLatitude()
method.

Q6 Write steps to deploy an android application. 4M


Ans Step 1: Make a Developer Account

A developer account is must be needed to upload an app on the Google Play Store,
and the process is very simple. Just go through Google Play Store and do as
instructed.

1. Sign-In with Your Google Account


2. Accept Terms
3. Pay Registration Fee of $25.
4. Complete Your Account Details
Step 2: After you completed step 1 you will be redirected to this page where you
have to click on the CREATE APPLICATION button.

 Once you click on it a pop up will be shown like this where you have to
choose your Default language and Title of your app. Then click on the
CREATE button.

Step 3: Store listing

 After you completed step 2 you will be redirected to this page where you
have to provide the Short description and Full description of your App.
 Then you scroll down the page and now you have to add the Hi-res icon of
your app. Then you have to provide the Screenshots of your app.
 And next thing you have to provide is the Feature Graphic of your app.
Note that this graphic is then used everywhere your app is featured on
Google Play.
 Then come to Categorization part where you have to provide your
Application type and Category of your app.
 And finally when you click on SAVE DRAFT button you can see that
Store listing tab is now become turned to green and you are done for Store
listing.

Step 4: App release

 After completing step 3 go to App releases then scroll down to


Production track and click on MANAGE button.
 After redirecting to the next page click on the CREATE RELEASE
button.
 After that on the next page, you have to upload your APK file in Android
App Bundles and APKs to add section.
 After that simply click on the SAVE button.

Step 5: Content rating

 Now after completing step 4 go to Content rating and click on


CONTINUE button.
 After that fill your email address as well as confirm the email address.
 And then Select your app category.
 After selecting your app category make sure that you read all of these and
answer them correctly.
 And after answering them correctly don’t forget to click on SAVE
QUESTIONNAIRE button.
 Once you saved all those things then click on CALCULATE RATING
button.
 When you redirected to another page scroll down and click on APPLY
RATING button. And you are done for Content rating section. Don’t
forget to notice that Content rating section is now become turned to
green.

Step 6: Pricing & distribution

 Then go to the Pricing & distribution section. Then select the country in
which you want to available your app.
 Then go down and down and check out the Content guidelines and US
export laws section by marking them tick mark. And click on the SAVE
DRAFT button. Don’t forget to notice that Pricing & distribution section
is now become turned to green tick.

Step 7: App content

 Then come to the App content section. And in the Privacy policy section
click on the Start button.
 And then provide a valid Privacy policy URL. Note that google will
check this.
 Then go back and continue further steps by clicking start button in Ads
section.
 Then select does your app contain ads or not? And click on SAVE
button.
 Then again go back and continue further steps by clicking start button in
Target audience and content section.
 In the next page select the Target age group and scroll down and click on
the Next button.
 Then check the Appeal to children section. And click on the Next button.
 On the next page click on the Save button and you are done for App
content section.

Step 8: App releases

 Again go back to the App releases section. And in the Production track
click on the EDIT RELEASE button.
 Then on the next page go down and down and click on the REVIEW
button.
 And finally, on the next page click on the START ROLLOUT TO
PRODUCTION button to send your app to review. And you are finally
done.
 After usually 4 to 5 days they will review your app and let you know to
either approve or reject your app.

Q7 . Explain Google Map with types. 2M


Ans Android provides facility to integrate Google map in our application. Google map
displays your current location, navigate location direction, search location etc. We
can also customize Google map according to our requirement
There are four different types of Google maps, as well as an optional to no map at
all. Each of them gives different view on map. These maps are as follow:
1. Normal: This type of map displays typical road map, natural features like river
and some features build by humans.
2. Hybrid: This type of map displays satellite photograph data with typical road
maps. It also displays road and feature labels.
3. Satellite: Satellite type displays satellite photograph data, but doesn't display
road and feature labels.
4. Terrain: This type displays photographic data. This includes colors, contour
lines and labels and perspective shading.
5. None: This type displays an empty grid with no tiles loaded
Q8 List various classes of SMS Telephony. 2M
Ans 1. Telephony.Sms.Conversations Contains a view of SMS conversations (also
referred to as threads).
2. Telephony.Sms.Draft Contains all draft text-based SMS messages in the SMS
app.
3. Telephony.Sms.Inbox Contains all text-based SMS messages in the SMS app
inbox.
4. Telephony.Sms.Intents Contains constants for SMS related Intents that are
broadcast. 5. Telephony.Sms.Outbox Contains all pending outgoing text-based
SMS messages.
6. Telephony.Sms.Sent Contains all sent text-based SMS messages in the SMS
ap
Q9 Describe types of permissions used while developing android applications. 4M
Ans Types of Permissions
1. Install-Time Permissions: If the Android 5.1.1 (API 22) or lower, the
permission is requested at the installation time at the Google Play Store. If the user
Accepts the permissions, the app is installed. Else the app installation is cancelled.
2. Run-Time Permissions: If the Android 6 (API 23) or higher, the permission is
requested at the run time during the running of the app. If the user Accepts the
permissions, then that feature of the app can be used. Else to use the feature, the
app requests the permission again.
Permission to:
Access sensitive user information
Optional hardware features
Activity permission
ervice permission
Broadcast permission
Content Provider permission
URI permissions
ormal permissions
Signature permissions
Dangerous permissions
Q10 Develop an application to send and receive SMS. (Write ONLY .java and 4M
permission tag in manifest file). (CO6)
Ans
SendSmsActivity.java
package com.javapapers.androidsms;
import android.app.Activity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class SendSmsActivity extends Activity {
Button sendSMSBtn;
EditText toPhoneNumberET;
EditText smsMessageET;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sms);
sendSMSBtn = (Button) findViewById(R.id.sendSMSBtn);
toPhoneNumberET = (EditText) findViewById(R.id.toPhoneNumberET);
smsMessageET = (EditText) findViewById(R.id.smsMessageET);
sendSMSBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
sendSMS();
}
});
}
protected void sendSMS() {
String toPhoneNumber = toPhoneNumberET.getText().toString();
M.M. Polytechnic, Thergaon
Computer Engineering Department Mrs. Chavan P.P.
String smsMessage = smsMessageET.getText().toString();
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(toPhoneNumber, null, smsMessage, null, null);
Toast.makeText(getApplicationContext(), "SMS sent.",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"Sending SMS failed.",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
}
SmsBroadcastReceiver.java
package com.javapapers.androidreceivesms;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;
public class SmsBroadcastReceiver extends BroadcastReceiver {
public static final String SMS_BUNDLE = "pdus";
public void onReceive(Context context, Intent intent) {
Bundle intentExtras = intent.getExtras();
if (intentExtras != null) {
Object[] sms = (Object[]) intentExtras.get(SMS_BUNDLE);
String smsMessageStr = "";
for (int i = 0; i < sms.length; ++i) {
SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sms[i]);
String smsBody = smsMessage.getMessageBody().toString();
String address = smsMessage.getOriginatingAddress();
smsMessageStr += "SMS From: " + address + "\n";
smsMessageStr += smsBody + "\n";
}
Toast.makeText(context, smsMessageStr, Toast.LENGTH_SHORT).show();
//this will update the UI with message
SmsActivity inst = SmsActivity.instance();
inst.updateList(smsMessageStr);
}
}

SmsActivity.java
package com.javapapers.androidreceivesms;
import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
public class SmsActivity extends Activity implements OnItemClickListener {
private static SmsActivity inst;
ArrayList<String> smsMessagesList = new ArrayList<String>();
ListView smsListView;
ArrayAdapter arrayAdapter;
public static SmsActivity instance() {
return inst;
}
@Override
public void onStart() {
super.onStart();
inst = this;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sms);
smsListView = (ListView) findViewById(R.id.SMSList);
arrayAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
smsMessagesList);
smsListView.setAdapter(arrayAdapter);
smsListView.setOnItemClickListener(this);
refreshSmsInbox();
}
public void refreshSmsInbox() {
ContentResolver contentResolver = getContentResolver();
Cursor smsInboxCursor =
contentResolver.query(Uri.parse("content://sms/inbox"), null,
null, null, null);
int indexBody = smsInboxCursor.getColumnIndex("body");
int indexAddress = smsInboxCursor.getColumnIndex("address");
if (indexBody < 0 || !smsInboxCursor.moveToFirst()) return;
arrayAdapter.clear();
do {
String str = "SMS From: " + smsInboxCursor.getString(indexAddress) +
"\n" + smsInboxCursor.getString(indexBody) + "\n";
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
public class SmsActivity extends Activity implements OnItemClickListener {
private static SmsActivity inst;
ArrayList<String> smsMessagesList = new ArrayList<String>();
ListView smsListView;
ArrayAdapter arrayAdapter;
public static SmsActivity instance() {
return inst;
}
@Override
public void onStart() {
super.onStart();
inst = this;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sms);
smsListView = (ListView) findViewById(R.id.SMSList);
arrayAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
smsMessagesList);
smsListView.setAdapter(arrayAdapter);
smsListView.setOnItemClickListener(this);
refreshSmsInbox();
}
public void refreshSmsInbox() {
ContentResolver contentResolver = getContentResolver();
Cursor smsInboxCursor =
contentResolver.query(Uri.parse("content://sms/inbox"), null,
null, null, null);
int indexBody = smsInboxCursor.getColumnIndex("body");
int indexAddress = smsInboxCursor.getColumnIndex("address");
if (indexBody < 0 || !smsInboxCursor.moveToFirst()) return;
arrayAdapter.clear();
do {
String str = "SMS From: " + smsInboxCursor.getString(indexAddress) +
"\n" + smsInboxCursor.getString(indexBody) + "\n";
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
public class SmsActivity extends Activity implements OnItemClickListener {
private static SmsActivity inst;
ArrayList<String> smsMessagesList = new ArrayList<String>();
ListView smsListView;
ArrayAdapter arrayAdapter;
public static SmsActivity instance() {
return inst;
}
@Override
public void onStart() {
super.onStart();
inst = this;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sms);
smsListView = (ListView) findViewById(R.id.SMSList);
arrayAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
smsMessagesList);
smsListView.setAdapter(arrayAdapter);
smsListView.setOnItemClickListener(this);
refreshSmsInbox();
}
public void refreshSmsInbox() {
ContentResolver contentResolver = getContentResolver();
Cursor smsInboxCursor =
contentResolver.query(Uri.parse("content://sms/inbox"), null,
null, null, null);
int indexBody = smsInboxCursor.getColumnIndex("body");
int indexAddress = smsInboxCursor.getColumnIndex("address");
if (indexBody < 0 || !smsInboxCursor.moveToFirst()) return;
arrayAdapter.clear();
do {
String str = "SMS From: " + smsInboxCursor.getString(indexAddress) +
"\n" + smsInboxCursor.getString(indexBody) + "\n";
arrayAdapter.add(str);
} while (smsInboxCursor.moveToNext());
}
public void updateList(final String smsMessage) {
arrayAdapter.insert(smsMessage, 0);
arrayAdapter.notifyDataSetChanged();
}
public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
try {
String[] smsMessages = smsMessagesList.get(pos).split("\n");
String address = smsMessages[0];
String smsMessage = "";
for (int i = 1; i < smsMessages.length; ++i) {
smsMessage += smsMessages[i];
}
String smsMessageStr = address + "\n";
smsMessageStr += smsMessage;
Toast.makeText(this, smsMessageStr, Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Permission tag
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />

Q11 Discuss Developer console with its purpose 4M


Ans The Android Things Console provides easy and secure deployment of updates to
your
connected devices. Google provides the infrastructure to host and deliver system
and app
updates with the developer in final control.
Using the console, developers and device makers can:
• Download and install the latest Android Things system image
• Build factory images that contain OEM applications along with the system image
• Push over-the-air (OTA) seamless updates, including OEM applications and the
system image,
to devices
• Manage and share OEM applications across products and owners
• Monitor informative analytics to understand how well products are performin
Q12 Describe location based services. List important methods 4m
The Location object signifies a geographic location which can consist of latitude,
longitude, time stamp. Also it consist other information such as altitude, bearing,
and velocity. There are following:-

important methods which you can use with Location object to get location specific
information –

getLatitude(): Get the latitude, in degrees.

getLongitude(): Get the longitude, in degrees.

distanceTo(Location dest): Provide the app distance in meters between this


location.

getAccuracy(): Get the estimated accuracy of this location, in meters.


getAltitude(): Get the altitude if available, in meters above sea level.

getSpeed(): Get the speed if it is available, in meters/second over

reset(): Clears the contents of the location.

toString(): Returns a string containing a concise, human-readable description of


this object.

To get the current location, create a location client which is LocationClient object,
connect it to Location Services using connect() method, and then call its
getLastLocation() method.

To have location based functionality in your activity, you will have to


implement two interfaces –

1.GooglePlayServicesClient.ConnectionCallbacks

2.GooglePlayServicesClient.OnConnectionFailedList ene
Model Answer Paper Question answer
Q1 a) List any four features of Android operating system.
Ans Features of Android Operating System:
1)Storage
2)Multitasking
3)Web Browser
4)Open Source
5)Accessibility
6)Media Support
7)Streaming Media Support 8)Voice Based Features
9)Multitouch
10)External Storage
11)Video Calling
12)Handset Layout
13)Google cloud Messaging 14)WiFi Direct
Q2 b) Define Dalvik Virtual Machine (DVM)
Ans Dalvik Virtual Machine is a register-based machine that compiles byte code to get dex code and
that ensures that a device can run multiple instances efficiently.
Q3 c) List any four folders from directory structure of Android project and elaborate in one
line.
Ans Folders from directory structure:
1)app: The App folder contains three subfolders (manifests, java and res) that make up our
application. They are divided so that it should be fairly easy to determine which resources go in
which folder.
2)Manifest: This is where we would put our manifest files. Most Android apps have single
manifest file. But an app may have several manifest files due to application versioning, or for
supporting specific hardware.
3)Java: This is the folder in our project where we will be storing all of the source code files
written in Java programming language.
4)res: It contains folders that help us to separate and sort the resources of our application.
Resources basically mean all the needed files except the source code. 5)drawable: The
drawable folder contains graphics that can be drawn to the screen. 6)layout: The layout folder
contains XML files used for your layouts. These file are used to set up the layout for your
Activity and is used for basic alignment of your layouts, components, widgets, and similar
resources that are used for the UI of your application. 7)mipmap : The mipmap folder contains
the launcher icon files for the app. A launcher icon is a graphic that represents your app to users.
8)values: The values folder contains XML files that contain simple values, such as strings,
integers, and colors. The values folder is used to keep track of the values we will be using in our
application.

Q4 d) List any four attributes of check box. 2 M


Ans 1)id
2)checked
3)gravity
4)text
5)text color
6)text size
7)text style
8)background
9)padding

Q5 e) Draw diagram of activity life cycle.


Ans
Q6 f) State syntax to display built in zoom control. 2 M
a) Built in Zoom control in Google map can be displayed with :
UiSettings.setZoomControlsEnabled(true);
OR
b) In case, while display Google map by intent, default zoom level can be given in
the form of data as
geo:latitude,longitude?z=zoom
where lat and lag are for location and zoom level is to set initial zoom level which
ranges from 0 to 21.
OR
c) In any normal activity, ZoomControl can be displayed as component by following
syntax :
ZoomControl zoomControls = (ZoomControls)
findViewById(R.id.simpleZoomControl);
zoomControls.show()
Q7 g) Name two classes used to play audio and video in Android. 2 M
Ans 1) MediaPlayer
2) MediaController
3) AudioManager

a) Describe Android architecture with diagram. 4 M


1. Applications:
• The top layer of android architecture is Applications. The native and third party
applications like Contacts, Email, Music, Gallery, Clock, Games, etc. whatever we will
build those will be installed on this layer only.
• The application layer runs within the Android run time using the classes and services
made available from the application framework.
2. Application Framework:
• The Application Framework provides the classes used to create an Android
application.
It also provides a generic abstraction for hardware access and manages the user
interface and application resources.
• It basically provides the services through which we can create the particular class and
make that class helpful for the Applications creation.
• The application framework includes services like telephony service, location services,
notification. manager, NFC service, view system, etc. which we can use for application
development as per our requirements.
3. Android Runtime:
• Android Runtime environment is an important part of Android rather than an internal
part and it contains a components like core libraries and the Dalvik virtual machine.
• The Android run time is the engine that powers our applications along with the
libraries
and it forms the basis for the application framework.
(i) Dalvik Virtual Machine (DVM) is a register-based virtual machine like Java Virtual
Machine (JVM).
It is specially designed and optimized for android to ensure that a device can run
multiple
instances efficiently. It relies on the Linux kernel for threading and low-level memory
management.
(ii) The core libraries in android runtime will enable us to implement an android
applications using standard JAVA programming language.
4. Platform Libraries:
• The Platform Libraries includes various C/C++ core libraries and Java based libraries
such as SSL, libc, Graphics, SQLite, Webkit, Media, Surface Manger, OpenGL etc. to
provide a support for android development.
• Following are the summary details of some core android libraries available for android
development.
• Media library for playing and recording an audio and video formats
(i) The Surface manager library to provide a display management
(ii) SGL and OpenGL Graphics libraries for 2D and 3D graphics
(iii) SQLite is for database support and FreeType for font support
(iv) Web-Kit for web browser support and SSL for Internet security.
5. Linux Kernel:
• Linux Kernel is a bottom layer and heart of the android architecture. It is heart of
Android
architecture that exists at the root of android architecture and contains all the low-level
device
drivers for the various hardware components of an Android device.
• Linux Kernel is responsible fro device drivers, power management, memory
management, device management and resource access. It manage all the drivers such as
display drivers, camera drivers,
Bluetooth drivers, audio drivers, memory drivers, etc. which are mainly required for the
android device during the runtime.
• The Linux Kernel will provides an abstraction layer between the device hardware and
the remainder of the stack. It is responsible for memory management, power
management, device management, resource access, etc.
b) Differentiate between DVM and JVM. 4 M
Ans
JVM(Java Virtual Machine) DVM(Dalvik Virtual Machine)
Stack-based VM that performs Register-based VM that uses registers
arithmetic and logic operations through located
push and pop operands. The result of in the CPU to perform arithmetic and
operations is stored in stack memory. logic operations.
Source code files are first of all compiled
into Java bytecode format like JVM.
Java source code is compiled into Java
Further, the DEX compiler(dx tool)
bytecode format(.class file) that further
converts the Java bytecode into Dalvik
translates into machine code.
bytecode(classes.dex) file
that will be used to create the .apk file.
More information is required to the VM
for data loading and manipulation as Instruction size is larger as it needs to
well as method loading in the stack encode the source and destination register of the VM.
data structure.
Compiled bytecode size is compact
Compiled bytecode size is larger as each
because the location of the operand is
instruction needs all implicit operands.
implicitly on the operand stack.
The executable file for the device is .jar The executable file for the device is
file. .apk file.
A single instance of JVM is configured
The device runs multiple DVM instances
with shared processes and memory
with a separate process in shared memory space to
space in order to run all deployed
deploy the code of each application.
applications.
Supports multiple operating systems Support only the Android operation
like Linux, Windows, and Mac OS. system.

c) List and elaborate steps to deploy an Android application on Google play


store.
Ans Steps to deploy and Android Application on Google Play Store:
Step 1: Make a Developer Account
Step 2: Plan to Sell? Link Your Merchant Account
Step 3: Create an App
Step 4: Prepare Store Listing
Step 5: Upload APK to an App Release
Step 6: Provide an Appropriate Content Rating
Step 7: Set Up Pricing & Distribution
Step 8: Rollout Release to Publish Your App
Step 1: Create a Developer Account
Before you can publish any app on Google Play, you need to create a Developer
Account.
You can easily sign up for one using your existing Google Account. You’ll need to pay a
one-time registration fee of $25 using your international credit or debit card. It can take
up to 48 hours for your registration to be fully processed.
Step 2: Plan to Sell? Link Your Merchant Account
If you want to publish a paid app or plan to sell in-app purchases, you need to create a
payments center profile, i.e. a merchant account. A merchant account will let you
manage
your app sales and monthly payouts, as well as analyze your sales reports right in your
Play Console.
Step 3: Create an App
Now you have create an application by clicking on 'Create Application'. Here you have
to select your app’s default language from the drop-down menu and then type in a title
for your app. The title of your app will show on Google Play after you’ve published.
Step 4: Prepare Store Listing
Before you can publish your app, you need to prepare its store listing. These are all the
details that will show up to customers on your app’s listing on Google Play. You not
necessarily complete it at once , you can always save a draft and revisit it later when
you’re ready to publish.
The information required for your store listing is divided into several categories such as
Product Details containing title, short and full description of the app, Your app’s title
and description should be written with a great user experience in mind. Use the right
keywords, but don’t overdo it. Make sure your app doesn’t come across as spam-y or
promotional, or it will risk getting suspended on the Play Store.
Graphic Assets where you can add screenshots, images, videos, promotional graphics,
and icons that showcase your app’s features and functionality.
Languages & Translations, Categorization where in category can be selected to which
your app belong to. Contact Details , Privacy Policy for apps that request access to
sensitive user data or permissions, you need to enter a comprehensive privacy policy
that
effectively discloses how your app collects, uses, and shares that data.
Step 5: Upload APK to an App Release
Finally upload your app, by uploading APK file. Before you upload APK, you need to
create an app release. You need to select the type of release you want to upload your
first
app version to. You can choose between an internal test, a closed test, an open test, and
a
production release. The first three releases allow you to test out your app among a select
group of users before you make it go live for everyone to access.
This is a safer option because you can analyze the test results and optimize or fix your
app accordingly if you need to before rolling it out to all users.
Once you create a production release, your uploaded app version will become
accessible
to everyone in the countries you choose to distribute it in and click on ‘Create release.’
Step 6: Provide an Appropriate Content Rating
If you don’t assign a rating to your app, it will be listed as ‘Unrated’. Apps that are
‘Unrated’ may get removed from Google Play.
To rate your app, you need to fill out a content rating questionnaire An appropriate
content rating will also help you get to the right audience, which will eventually
improve
your engagement rates.
Step 7: Set Up Pricing & Distribution
Before you can fill out the details required in this step, you need to determine your
app’s
monetization strategy. Once you know how your app is going to make money, you can
go
ahead and set up your app as free or paid.
You can always change your app from paid to free later, but you cannot change a free
app
to paid. For that, you’ll need to create a new app and set its price.
Step 8: Rollout Release to Publish Your App
The final step involves reviewing and rolling out your release after making sure you’ve
taken care of everything else.
Before you review and rollout your release, make sure the store listing, content rating,
and pricing and distribution sections of your app each have a green check mark next to
them.
Once you’re sure about the correctness of the details, select your app and navigate to
‘Release management’ – ‘App releases.’ You can always opt for reviews by clicking on
‘Review’ to be taken to the ‘Review and rollout release’ screen. Here, you can see if
there
are any issues or warnings you might have missed out on.
Finally, select ‘Confirm rollout.’ This will also publish your app to all users in your
target
countries on Google Play.
d) Describe with example, how to create a simple database in SQLite (Assume
suitable data).
(Note : Any other method such as creating subclass of SQLiteOpenHelper class
and overriding and using required methods with relevant example can also be
considered)4M
Ans This procedure is by openOrCreateDatabase()
1. The package imported into the application is android.database.sqlite.SQLiteDatabase.
2. Here the class used is SQLiteDatabase.
3. The method used to create the database or connect to the database is
openOrCreateDatabse() method.
Program:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
Description 1 M, 1 M for XML file , 2 M for Java
File)
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:text="Create SQLite Database"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="46dp"
android:id="@+id/button" />
</RelativeLayout>
MainActivity.java
package in.edu.vpt.insertusingasync;
import android.app.ProgressDialog;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;;
public class MainActivity extends AppCompatActivity {
SQLiteDatabase sqLiteDatabaseObj;
Button EnterData;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
createData = (Button)findViewById(R.id.button);
createData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sqLiteDatabaseObj = openOrCreateDatabase("AndroidJSonDataBase",
Context.MODE_PRIVATE, null);
} });
}
3. Attempt any THREE of the following: 12 M
a) Write down the steps to install and configure Android studio. 4 M
Ans
Step 1: Go to https://developer.android.com/android-studio/download to get the
Android
Studio executable or zip file.

Step 2:
● Click on the Download Android Studio Button.
● Click on the “I have read and agree with the above terms and conditions”
checkbox followed by the download button
● Click on the Save file button in the appeared prompt box and the file will start
downloading.
Step 3: After the downloading has finished, open the file from downloads and will
prompt the following dialog box. Click on next. In the next prompt, it’ll ask for a path
for
installation. Choose a path and hit next.
Step 4: It will start the installation, and once it is completed, it will be like the image
shown below.
Step 5: Once “Finish” is clicked, it will ask whether the previous settings need to be
imported [if the android studio had been installed earlier], or not. It is better to choose
the
‘Don’t import Settings option’. Click the OK button.
Step 6: This will start the Android Studio. Meanwhile, it will be finding the available
SDK components.
Step 7: After it has found the SDK components, it will redirect to the Welcome dialog
box.
Choose Standard and click on Next. Now choose the theme, whether the Light theme or
the Dark one. The light one is called the IntelliJ theme whereas the dark theme is
called Darcula. Choose as required. Click on the Next button.
Step 8: Now it is time to download the SDK components. Click on Finish. Components
begin to download let it complete. The Android Studio has been successfully
configured. Now it’s time to launch and build apps. Click on the Finish button to launch
it.
Step 9: Click on Start a new Android Studio project to build a new app.
steps)
b) State syntax to create Text View and Image button with any two attributes of
each. 4 M
Ans Text View:
Syntax :
<TextView
android:id="@+id/textView1"
android:layout_width="<width value>”
android:layout_height="<height_value>"
android:text="<text to be displayed>"/>
Attributes/Properties of TextView:
● id: Supply an identifier name of this view, to later retrieve it with
View.findViewByID() or Activity.findViewById()
● alpha: alpha property of the view as a value between 0 (entirely transparent) and
1(Completely Opaque). [flag]
● auto link: Controls whether links such as urls and email addresses are
automatically found and converted to clickable links.[flag]
● gravity: The gravity attribute is an optional attribute which is used to control the
alignment of the text like left, right, center, top, bottom, center_vertical,
center_horizontal etc
● text: text attribute is used to set the text in a text view. We can set the text in xml as
(Syntax of
TextView
and
ImageButton 1 M each Any two appropriate attributes of each : 1/2 M each)
well as in the java class.
● textColor: textColor attribute is used to set the text color of a text view. Color
value is in the form of “#argb”, “#rgb”, “#rrggbb”, or “#aarrggbb”.
● textSize: textSize attribute is used to set the size of text of a text view. We can set
the text size in sp(scale independent pixel) or dp(density pixel).
● textStyle: textStyle attribute is used to set the text style of a text view. The possible
text styles are bold, italic and normal. If we need to use two or more styles for a text
view then “|” operator is used for that.
● background: background attribute is used to set the background of a text view. We
can set a color or a drawable in the background of a text view.
● padding: padding attribute is used to set the padding from left, right, top or bottom.
In above example code of background we also set the 10dp padding from all the
sides of text view.
ImageButton:
Syntax :
<ImageButton
android:id="@+id/imageButton"
android:layout_width="<width value>"
android:layout_height="<height value>"
app:srcCompat="<image source from drawable folder "/>
Attributes/Properties of ImageButton:
● id: id is an attribute used to uniquely identify a image button. Below is the
example code in which we set the id of a image button.
● src: src is an attribute used to set a source file of image or you can say image in
your image button to make your layout look attractive.
● background: background attribute is used to set the background of an image
button. We can set a color or a drawable in the background of a Button.
● padding: padding attribute is used to set the padding from left, right, top or
bottom of the ImageButton.
c) Describe Android service life cycle along with diagram. 4 M
Ans
● A service is an application component which runs without direst interaction with
the user in the background.
● Services are used for repetitive and potentially long running operations, i.e.,
Internet downloads, checking for new data, data processing, updating content
providers and the like.
● Service can either be started or bound we just need to call either startService() or
bindService() from any of our android components. Based on how our service
was started it will either be “started” or “bound”
(Explanation 2 M, Diagram 2M)
Service Lifecycle
1. Started
a. A service is started when an application component, such as an activity,
starts it by calling startService().
b. Now the service can run in the background indefinitely, even if the
component that started it is destroyed.
2. Bound
a. A service is bound when an application component binds to it by calling
bindService().
b. A bound service offers a client-server interface that allows components to
interact with the service, send requests, get results, and even do so across
processes with InterProcess Communication (IPC).
c. Like any other components service also has callback methods. These will
be invoked while the service is running to inform the application of its
state. Implementing these in our custom service would help you in
performing the right operation in the right state. •
d. There is always only a single instance of service running in the app. If you
are calling startService() for a single service multiple times in our
application it just invokes the onStartCommand() on that service. Neither
is the service restarted multiple times nor are its multiple instances created
1. onCreate():
This is the first callback which will be invoked when any component starts the
service. If the same service is called again while it is still running this method
wont be invoked. Ideally one time setup and intializing should be done in this
callback.
2. onStartCommand() /startSetvice()
This callback is invoked when service is started by any component by calling
startService(). It basically indicates that the service has started and can now run
indefinetly.
3. onBind()
To provide binding for a service, you must implement the onBind() callback
method. This method returns an IBinder object that defines the programming
interface that clients can use to interact with the service.
4. onUnbind()
This is invoked when all the clients are disconnected from the service.
5. onRebind()
This is invoked when new clients are connected to the service. It is called after
onRebind
6. onDestroy()
This is a final clean up call from the system. This is invoked just before the
service is being destroyed.
d) State and elaborate the syntax of required class and methods for
Geocoding. 4 M
Ans
Geocoder:
A class for handling geocoding and reverse geocoding.
Geocoding is the process of transforming a street address or other description of a
location into a (latitude, longitude) coordinate.
Reverse geocoding is the process of transforming a (latitude, longitude) coordinate into
a (partial) address. The amount of detail in a reverse geocoded location description may
vary, for example one might contain the full street address of the closest building, while
another might contain only a city name and postal code.
The Geocoder class requires a backend service that is not included in the core android
framework.
The Geocoder query methods will return an empty list if there no backend service in the
platform. Use the isPresent() method to determine whether a Geocoder implementation
exists.
Syntax
Geocoder (Context context)
Constructs a Geocoder localized for the default locale.
Geocoder(Context context, Locale locale)
Constructs a Geocoder localized for the given locale.
Methods with Syntax
a. getFromLocation
Syntax
public List<Address> getFromLocation (double latitude, double longitude, int
maxResults)
public void getFromLocation (double latitude, double longitude, int maxResults,
Geocoder.GeocodeListener listener)
This method returns an array of Addresses that attempt to describe the area immediately
surrounding the given latitude and longitude. The returned addresses should be
localized
for the locale provided to this class's constructor.
b. getFromLocationName
Syntax :
● public List<Address> getFromLocationName (String locationName, int
maxResults, double lowerLeftLatitude, double lowerLeftLongitude, double
upperRightLatitude, double upperRightLongitude)
● public void getFromLocationName (String locationName, int maxResults,
double lowerLeftLatitude, double lowerLeftLongitude, double
upperRightLatitude, double upperRightLongitude, Geocoder.GeocodeListener
listener)
● public void getFromLocationName (String locationName, int maxResults,
Geocoder.GeocodeListener listener)
● public List<Address> getFromLocationName (String locationName, int
maxResults)
Returns an array of Addresses that attempt to describe the named location, which may
be
a place name such as "Dalvik, Iceland", an address such as "1600 Amphitheatre
Parkway,
Mountain View, CA", an airport code such as "SFO", and so forth. The returned
addresses should be localized for the locale provided to this class's constructor.
c. isPresent
public static boolean isPresent ()
Returns true if there is a geocoder implementation present that may return results. If
true,
there is still no guarantee that any individual geocoding attempt will succeed.
4. Attempt any THREE of the following: 12 M
a) Explain with example, code to create GUI using absolute layout
(Assume suitable data).4 M
Ans
● AbsoluteLayout is based on the simple idea of placing each control at an absolute
position. We specify the exact x and y coordinates on the screen for each control.
This is not recommended for most UI development (in fact AbsoluteLayout is
currently deprecated) since absolutely positioning every element on the screen makes
an inflexible UI that is much more difficult to maintain.
Absolute Layout
● An Absolute Layout lets you specify exact locations (x/y coordinates) of its children.
Absolute layouts are less flexible and harder to maintain than other types of layouts
without absolute positioning. AbsoluteLayout is based on the simple idea of placing
each control at an absolute position.
● We specify for the exact x and y corodinates on the screen for every control. So this
recommended for most UI development (in fact Absolute Layout is currentaly
deprecated)since absolute positioning of every element on the screen makes an
inflexible UI that is much more difficult to maintain.
● Consider what happens if a control needs to be added to the user interface UI, we
would have to change the position of every single element that is shifted by the new
control. This allows child views to be positioned at specified X and Y coordinates
within the containing layout view.
Example
(Note :Any other relevant example using absoluteLayout can be considered, No
java
code is expected)(Explanation 2 M, Example 2 M)
activity_main.xml
<AbsoluteLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_x="110px"
android:layout_y="110px"
android:text="User Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:layout_x="250px"
android:layout_y="80px"
android:width="100px"
android:layout_width="200dp"
android:layout_height="wrap_content" />
<TextView
android:layout_x="110px"
android:layout_y="200px"
android:text="Password"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:layout_x="250px"
android:layout_y="150px"
android:width="100px"
android:layout_width="200dp"
android:layout_height="wrap_content" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Log In"
android:layout_x="300px"
android:layout_y="300px"/>
</AbsoluteLayout>
b) Write a program to demonstrate Date and Time picker.
(Note: Consider the appropriate XML file. All attributes are not required.
In java file all imports are not expected. Different relevant logic/code can be
considered.)
4M
Ans 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:layout_width="match_parent"
(2M for correct use of Date picker2M for

android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/tvDate"
android:layout_width="149dp"
android:layout_height="46dp"
android:layout_marginEnd="224dp"
android:layout_marginBottom="312dp"
android:textSize="20dp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="@+id/btnDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="96dp"
android:layout_marginBottom="312dp"
android:text="Set Date"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:ignore="DuplicateClickableBoundsCheck" />
<DatePicker
android:id="@+id/dtpcker"
android:layout_width="314dp"
android:layout_height="293dp"
android:layout_marginBottom="368dp"
android:datePickerMode="spinner"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.36"
app:layout_constraintStart_toStartOf="parent" />
<TimePicker
android:id="@+id/timepcker"
android:layout_width="184dp"
android:layout_height="195dp"
android:layout_marginEnd="132dp"
android:layout_marginBottom="108dp"
android:timePickerMode="spinner"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="@+id/tvTime"
android:layout_width="130dp"
android:layout_height="56dp"
android:layout_marginEnd="232dp"
android:layout_marginBottom="40dp"
android:textSize="20dp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="@+id/btnTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="104dp"
android:layout_marginBottom="48dp"
android:text="Set Time"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.datepickereg;
import androidx.appcompat.app.AppCompatActivity;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.TimePicker;
import java.util.Calendar;
public class MainActivity extends AppCompatActivity {
TextView tvDate,tvTime;
DatePicker dtpcker;
TimePicker timepcker;
Button b1,b2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvDate=findViewById(R.id.tvDate);
tvTime=findViewById(R.id.tvTime);
b1=findViewById(R.id.btnDate);
b2=findViewById(R.id.btnTime);
dtpcker=findViewById(R.id.dtpcker);
timepcker=findViewById(R.id.timepcker);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
tvDate.setText("Date : "+dtpcker.getDayOfMonth()+"-
"+dtpcker.getMonth()+"-"+dtpcker.getYear());
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

tvTime.setText(timepcker.getCurrentHour()+":"+timepcker.getCurrentMinute());
}
});
}
}
c) Describe multimedia framework of Android with diagram. 4 M
Ans
● The android multimedia system includes multimedia applications, multimedia
frameworks, OpenCore engine and hardware abstract for audio/video input/output
devices. And the goal of the android multimedia framework is to provide a
reliable interface for java services. The multimedia framework consists of several
core dynamic libraries such as libmediajni, libmedia, libmediaplayservice and so
on.
● Java classes call the Native C library Libmedia through Java JNI(Java Native
Interface). Libmedia library communications with Media Server guard process
through Android’s Binder IPc (inter process communication) mechanism.
● Media Server process creates the corresponding multimedia service according to
the Java multimedia applications.
● The whole communication between Libmedia and Media Server forms a
Client/Server model
Android Multimedia Framework Architecture

(Explanation 2M, Diagram 2 M)


● Typical video/audio data stream works in Android as follows. Particularly, Java
applications first set the URI of the media (from file or network) to PVPlayer
through Java framework, JNI and Native C. In this process, there are no data
stream flows.
● Then PVPlayer processes the media data stream with the steps: demux the media
data to separate video/audio data stream, decode video/audio data, sync
video.audio time, send the decoded data out.
● The below is the description of media codec/format, container and network
protocol supported by the Android platform.
1. Container: The audio file format is a file for storing digital audio data on
a system. This data can be manipulated to reduce the size or change the
quality of the audio. It is a kind of container to store audio information.
2. Audio Format: Any format or codec can be used including the ones
provided by Android or those which are specific devices. However it is
recommended to use the specified file formats as per devices.
3. Network Protocol: Protocols such as RTSP, HTTP,HTTPS are supported
in audio and video playback.
d) Discuss developer console with at least four features 4 M
Ans
● Google Play Developer Console is the platform that Google provides for Google
Play and Android developers to publish their apps.
● The Google Play Developer console allows app developers and marketers to
better understand how their apps are performing in terms of growth, technical
performance such as crashes or display issues, and financials.
● The console offers acquisition reports and detailed analysis which can help app
devs find out how well an app is really performing.
● The platform is important as it provides developers with access to first party data
(trustworthy information collected about an app’s audience that comes straight
from Google Play) that highlights the real performance of an app.
● It shows the number of impressions an app listing receives and the number of

e) Write a program to demonstrate declaring and using permissions


with any relevant example.4 M
Ans
Permission declaring :
The permissions are declared in AndroidManifest.xml file under Manifest folder.
Permission can be set by <uses-permission> tag in AndroidManifest.xml.
Example:
Following example is to send SMS.
(Note: Any other relevant example which uses permissions can be considered)
AndroidManifest.xml
4 M for any
correct
program
demonstratin
g declaration
and use of
permissions
<uses-permission android:name="android.permission.SEND_SMS"/>
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="81dp"
android:layout_height="41dp"
android:layout_marginEnd="268dp"
android:layout_marginBottom="576dp"
android:text="To :"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView
android:id="@+id/textView2"
android:layout_width="70dp"
android:layout_height="43dp"
android:layout_marginEnd="276dp"
android:layout_marginBottom="512dp"
android:text="Sms Text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<EditText
android:id="@+id/etPhno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="40dp"
android:layout_marginBottom="572dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<EditText
android:id="@+id/etmsg"
android:layout_width="193dp"
android:layout_height="51dp"
android:layout_marginEnd="56dp"
android:layout_marginBottom="504dp"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:ignore="SpeakableTextPresentCheck" />
<Button
android:id="@+id/btnSms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="156dp"
android:layout_marginBottom="400dp"
android:text="SEND SMS"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.testreceivesms;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.Manifest;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText et1,et2;
Button b1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1=findViewById(R.id.etPhno);
et2=findViewById(R.id.etmsg);
b1=findViewById(R.id.btnSms);
if(ContextCompat.checkSelfPermission(MainActivity.this,Manifest.permission.SEN
D_SMS)!=
PackageManager.PERMISSION_GRANTED)
{
ActivityCompat.requestPermissions(MainActivity.this,new
String[]{Manifest.permission.SEND_SMS},100);
}
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
String phno= et1.getText().toString();
String msg=et2.getText().toString();
SmsManager smsManager= SmsManager.getDefault();
smsManager.sendTextMessage(phno,null,msg,null,null);
Toast.makeText(MainActivity.this,"Sms sent successfully",
Toast.LENGTH_LONG).show();
}
catch(Exception e)
{
Toast.makeText(MainActivity.this,"Sms failed to send... try again",
Toast.LENGTH_LONG).show();
}
}
});
}
}
5. Attempt any TWO of the following: 12 M
a) Write a program to convert temperature from celcius to farenhite and vice versa
using Toggle button. (Design UI as per your choice. Write XML and java file)
(Note: Consider the appropriate XML file. All attributes are not required.
In java file all imports are not expected. Different relevant logic/code can be
considered.)6 M
Ans activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edittext"
android:hint="Enter the temp"/>
<ToggleButton
android:id="@+id/togglebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/edittext"
android:layout_marginTop="35dp"
android:textOff="F to C"
android:textOn="C to F" />
XML file: 2M
Java Code:
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/togglebutton"
android:layout_marginTop="56dp" />
</RelativeLayout>
MainActivity.java
package com.example.p1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.widget.ToggleButton;
public class MainActivity extends AppCompatActivity {
Button b1;
EditText et;
ToggleButton tb;
Double a;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et=findViewById(R.id.edittext);
b1=findViewById(R.id.button);
tb=findViewById(R.id.togglebutton);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(tb.isChecked())
{
a=Double.parseDouble(String.valueOf(et.getText()));
Double b=a*9/5+32;
String r=String.valueOf(b);
Toast.makeText(MainActivity.this,r+"°F",Toast.LENGTH_SHORT).show();
}
else
{
a=Double.parseDouble(String.valueOf(et.getText()));
Double b=a-32;
Double c=b*5/9;
String r=String.valueOf(c);

Toast.makeText(MainActivity.this,r+"°C",Toast.LENGTH_SHORT).show();
}
}
});
}
}
b) Write a program to capture an image using camera and display it.
(Note: Consider the appropriate XML file. All attributes are not required.
In java file all imports are not expected. Different relevant logic/code can be
considered.)
6M
Ans activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="40dp"
android:orientation="horizontal"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CAMERA"
android:id="@+id/text"
android:textSize="20dp"
android:gravity="center"/>
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
android:layout_marginTop="81dp"
android:src="@drawable/rose"/>
<Button
android:id="@+id/photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/image"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="TAKE PHOTO" />
</RelativeLayout>
XML file:
2M Java Code: 4M
MainActivity.java
package com.example.ifcdiv;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
Button b1;
ImageView imageView;
int CAMERA_REQUEST=1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=findViewById(R.id.photo);
imageView=findViewById(R.id.image);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i,CAMERA_REQUEST);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent
data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==CAMERA_REQUEST)
{
Bitmap image= (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(image);
}
}
}

c) Develop and application to send and receive SMS (Design minimal UI as per
your choice. Write XML, java and manifest file)
(Note: Consider appropriate XML file. All attributes are not required. In java
file all imports are not expected. Different relevant login/code can be considered.
Statements showing permissions can be written under AndroidManifest.xml)
6M
Ans
Permissions and <receiver> tag required in AndroidManifest.xml
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.WRITE_SMS"/>
<receiver
android:name=".SmsReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="81dp"
android:layout_height="41dp"
android:layout_marginEnd="268dp"
android:layout_marginBottom="576dp"
android:text="To :"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView
android:id="@+id/textView2"
android:layout_width="70dp"
android:layout_height="43dp"
android:layout_marginEnd="276dp"
android:layout_marginBottom="512dp"
android:text="Sms Text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
XML file:
1M
Manifest
File:1M
Java Code:
4M
<EditText
android:id="@+id/etPhno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="40dp"
android:layout_marginBottom="572dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<EditText
android:id="@+id/etmsg"
android:layout_width="193dp"
android:layout_height="51dp"
android:layout_marginEnd="56dp"
android:layout_marginBottom="504dp"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:ignore="SpeakableTextPresentCheck" />
<Button
android:id="@+id/btnSms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="156dp"
android:layout_marginBottom="400dp"
android:text="SEND SMS"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.testreceivesms;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.Manifest;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


SmsReceiver sms= new SmsReceiver();
EditText et1,et2;
Button b1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1=findViewById(R.id.etPhno);
et2=findViewById(R.id.etmsg);
b1=findViewById(R.id.btnSms);
if(ContextCompat.checkSelfPermission(MainActivity.this,Manifest.permission.SEN
D_SMS)!=
PackageManager.PERMISSION_GRANTED)
{
ActivityCompat.requestPermissions(MainActivity.this,new
String[]{Manifest.permission.SEND_SMS},100);
}
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
String phno= et1.getText().toString();
String msg=et2.getText().toString();
SmsManager smsManager= SmsManager.getDefault();
smsManager.sendTextMessage(phno,null,msg,null,null);
Toast.makeText(MainActivity.this,"Sms sent successfully",
Toast.LENGTH_LONG).show();
}
catch(Exception e)
{
Toast.makeText(MainActivity.this,"Sms failed to send... try again",
Toast.LENGTH_LONG).show();
}
}
});
}
@Override
protected void onStart() {
super.onStart();
IntentFilter filter=new
IntentFilter("android.provider.Telephony.SMS_RECEIVED");
registerReceiver(sms,filter);
}
@Override
protected void onStop() {
super.onStop();
unregisterReceiver(sms);
}
}
SmsReceiver.java
package com.example.testreceivesms;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;
public class SmsReceiver extends BroadcastReceiver {
SmsReceiver(){}
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
// Retrieve the SMS Messages received
Object[] sms = (Object[]) bundle.get("pdus");
// For every SMS message received
for (int i=0; i < sms.length; i++) {
// Convert Object array
SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sms[i]);
String phone = smsMessage.getOriginatingAddress();
String message = smsMessage.getMessageBody().toString();
Toast.makeText(context, “Received from “+ phone + ": " + message,
Toast.LENGTH_SHORT).show();
}
}
}
}
6. Attempt any TWO of the following: 12 M
a) Write a program to implement Android Activity Life Cycle. Use toast messages
to display message through life cycle.
(Note: No XML code is required. In java file all imports are not expected.)
6M
Ans package com.example.p1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
Use of any 6
methods of
Activity life
cycle : 1 M
each
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast.makeText(getApplicationContext(),"Activity
created",Toast.LENGTH_LONG).show();
}
@Override
protected void onStart() {
super.onStart();
Toast.makeText(getApplicationContext(),"Activity
Started",Toast.LENGTH_LONG).show();
}
@Override
protected void onStop() {
super.onStop();
Toast.makeText(getApplicationContext(),"Activity
Stop",Toast.LENGTH_LONG).show();
}
@Override
protected void onDestroy() {
super.onDestroy();
Toast.makeText(getApplicationContext(),"Activity
Destroy",Toast.LENGTH_LONG).show();
}
@Override
protected void onPause() {
super.onPause();
Toast.makeText(getApplicationContext(),"Activity
Pause",Toast.LENGTH_LONG).show();
}
@Override
protected void onRestart() {
super.onResume();
Toast.makeText(getApplicationContext(),"Activity
Restart",Toast.LENGTH_LONG).show();
@Override
protected void onResume() {
super.onResume();
Toast.makeText(getApplicationContext(),"Activity
Resume",Toast.LENGTH_LONG).show();
}
}
b) Develop an application to display Google map with user's current location.
(Note : Consider the appropriate XML file. All attributes are not required.
6M

In java file all imports are not expected. Different relevant logic/code can be
considered.)
Ans act ivity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<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>
MainActivity.Java
package com.example.location;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.FragmentActivity;
import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
public class MainActivity extends FragmentActivity implements OnMapReadyCallback
{
Location currentlocation;
XML file: 1MJava Code: 5M
FusedLocationProviderClient fusedLocationProviderClient;
private static final int REQUEST_CODE = 101;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fusedLocationProviderClient =
LocationServices.getFusedLocationProviderClient(this);
fetchLastLocation();
}
private void fetchLastLocation() {
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,new
String[]{Manifest.permission.ACCESS_FINE_LOCATION},REQUEST_CODE);
return;
}
Task<Location> task = fusedLocationProviderClient.getLastLocation();
task.addOnSuccessListener(new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
if(location!=null)
{
currentlocation=location;

Toast.makeText(getApplicationContext(),currentlocation.getLatitude()+""+current
location.getLongitude(), Toast.LENGTH_SHORT).show();
SupportMapFragment supportMapFragment =
(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.go
ogle_map);
supportMapFragment.getMapAsync(MainActivity.this);
}
}
});
}
@Override
public void onMapReady(@NonNull GoogleMap googleMap) {
LatLng latLng=new
LatLng(currentlocation.getLatitude(),currentlocation.getLongitude());
MarkerOptions markerOptions=new MarkerOptions().position(latLng)
.title("I am Here");
googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng,5));
googleMap.addMarker(markerOptions);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[]
permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case REQUEST_CODE:
if (grantResults.length > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
fetchLastLocation();
}
break;
}
}
}
c) Design UI using table layout to display buttons with 0 9 numbers on it. Even display
submit and clear button. When user clicks on particular buttons and later when
clicks on submit button, it should display the numbers clicked.
(Note: Consider the appropriate XML file. All attributes are not required.
In java file all imports are not expected. Different relevant logic/code can be
considered.)
6M
Ans activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout 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"
android:stretchColumns="*"
tools:context=".MainActivity">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
XML file: 3M Java Code: 3M
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/button0"
android:text="0"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/button1"
android:text="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:text="2" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/button3"
android:text="3"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/button4"
android:text="4"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
android:id="@+id/button5"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="6"
android:id="@+id/button6"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="7"
android:id="@+id/button7"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8"
android:id="@+id/button8"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="9"
android:id="@+id/button9"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Submit"
android:id="@+id/submit"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Clear"
android:id="@+id/clear"/>
</TableRow>
</TableLayout>
(Java File)
package com.example.p1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Button button0, button1, button2, button3, button4, button5, button6,button7,
button8, button9,submit,clear;
String a=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button0 = (Button) findViewById(R.id.button0);
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button3 = (Button) findViewById(R.id.button3);
button4 = (Button) findViewById(R.id.button4);
button5 = (Button) findViewById(R.id.button5);
button6 = (Button) findViewById(R.id.button6);
button7 = (Button) findViewById(R.id.button7);
button8 = (Button) findViewById(R.id.button8);
button9 = (Button) findViewById(R.id.button9);
submit=(Button) findViewById(R.id.submit);
clear=(Button) findViewById(R.id.clear);
button0.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
a=button0.getText().toString();
}
});
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
a=button1.getText().toString();
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
a=button2.getText().toString();
}
});
button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
a=button3.getText().toString();
}
});
button4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
a=button4.getText().toString();
}
});
button5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
a=button5.getText().toString();
}
});
button6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
a=button6.getText().toString();
}
});
button7.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
a=button7.getText().toString();
}
});
button8.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
a=button8.getText().toString();
}
});
button9.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
a=button9.getText().toString();
}
});
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

Toast.makeText(getApplicationContext(),a,Toast.LENGTH_LONG).show(); }
});
}
}

You might also like