chapter wise notes
chapter wise notes
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.
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.
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
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
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:
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.
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
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 −
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
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.
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.
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.
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.
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.
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.
Disadvantages
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.
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
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 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.
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.
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
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.
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
1. Activities
2. Service
3. Content Providers
4. Broadcast Receiver
5.Widgets
6. View
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:
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?
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.
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.
2)Services
3) Broadcast Receivers
4)Content Providers
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.
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.
normal - 0
bold - 1
italic - 2
Create
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.
<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
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)
<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;
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);
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.
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.
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.
onResume called when activity will start interacting with the user.
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
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;
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 6: Upload APK. ... Complete the checklist on the left until all the items have
a green checkmark
4. double getLatitude()
5. double getLongitude()
6. float getSpeed()
Using setAltitude(), you can set the altitude of your place from sea level in metres.
Using the setBearing() method, you can set location bearing in degrees.
You can even set your location to some other latitude using the setLatitude()
method.
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.
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.
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.
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.
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.
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.
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" />
important methods which you can use with Location object to get location specific
information –
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.
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.
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
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;
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(); }
});
}
}