You are on page 1of 296

Chapter

Unit I 04

Android andand
Networking it’s Tool
Security
Hours: 04 Marks: 04

Presented by:

Prof.S.S.Bhosale
Pravara Polytechnic Loni
Socket
Specific Objective

Interpret features of Android operating system.


❑ Network socket is an endpoint of an inter-
process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
Introduction to Android

❑ Network socket is an endpoint of an inter-


process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
ANDROID
Socket
Introduction to Android
⚫ Google developed a mobile operating system
Network
❑based socket
on Linux is called
kernel an endpoint of an inter-
an Android
process communication flow across a
Operating
computerSystem.
network.
⚫Android is an open source Linux-based operating
❑ Sockets provide the communication
system intended
mechanism for mobile
between twocomputing platforms.
computers using
TCP/IP.
Socket
Introduction to Android
⚫ It is a software stack for mobile operating system.
❑ Network
⚫ Android socket
is under is an endpoint
development of anand
by Google inter-
Open-
process communication flow across a
Handset
computer Alliance.
network.
• There are more than 4,00,000 apps
in android market
❑ Sockets provide the communication
mechanism between two computers using
TCP/IP.
Socket
Introduction to Android
1.1.1 Open handset Alliance (OHA)
▪ The OHA is a business alliance that was created for
❑ Network socket is an endpoint of an inter-
theprocess
purpose communication flow
of developing open across
mobile a
device
computer network.
standard.
▪ The OHA is a group of more than 80 companies,
❑ Sockets provide the communication
mechanism
including between
Google, two Intel,
HTC, Dell, computers using
Motorola,
TCP/IP.
QUALCOMM.
▪Android is open to everyone ie, developer ,designer
and device maker.
Socket
ORIGIN OF ANDROID

Android was founded in Palo Alto, California


in Network
❑ socket
October 2003 byisAndy
an endpoint
Rubin,of an inter-
Rich Miner,
process communication flow across a
Nick Sears and Chris White who work at
computer network.
“Google” to develop.
❑ Sockets provide the communication
mechanism between two computers using
TCP/IP.
Andy Rubin
Socket
Introduction to Android

• Founded by Andy Rubin in year 2003.


❑ Network socket is an endpoint of an inter-
• Google
processacquired
communication
Androidflow – August
,Inc.across a 2005
computer
for network.
50 million $.
• The open handset alliance, a group of
❑ Sockets provide the communication
several companies was formed – 5 th
mechanism between two computers using
TCP/IP. 2007.
November
• Android Beta SDK Released – 12th November
2007.
Socket
ANDROID VERSIONS
• Android is released in series of Versions. Starting from 1.0
Network
❑version ( where 2.0, 3.0,is……
socket an endpoint of an).inter-
are latest releases
process
• Google name communication
these versions withflow
someacross a like ice
food items
computer
cream, network.
jelly bean, sandwich etc. which is one of the
specialty of android versions.
❑ Sockets provide the communication
mechanism between two computers using
TCP/IP.
Socket
ANDROID VERSIONS

❑ Network socket is an endpoint of an inter-


process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
ANDROID VERSIONS

❑ Network socket is an endpoint of an inter-


process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
ANDROID 1.0 (ALPHA)

Initial release date September 23, 2008


❑ Network socket is an endpoint of an inter-
process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
ANDROID 1.1 (BETA)

Initial release date February 9, 2009

❑ Network socket is an endpoint of an inter-


process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
CUPCAKE ANDROID 1.5 API LEVEL 3

• Released on April 27, 2009


• Support forsocket
❑ Network Widgets.is an endpoint of an inter-
•process
Animatedcommunication
screen flow across a
computer
transitions, network.
Auto-rotation
option.
❑•Sockets provide
Ability to upload the communication
videos
mechanism between two computers using
to YouTube, Picasa.
TCP/IP.
Socket
DONUT ANDROID 1.6 API LEVEL 4

• Released on September
❑ Network socket is an endpoint of an inter-
15, 2009.
process communication
• Quick search box. flow across a
computer network.
• Screen size diversity.
❑ Sockets provide
• Google play. the communication
mechanism between two computers using
TCP/IP.
Socket
ECLAIR ANDROID 2 API LEVEL 5,6,7

• Released on October
❑ Network socket is an endpoint of an inter-
26, 2009.
process
• Google communication
maps navigation. flow across a
computer network.
•Home screen
❑ Sockets provide the communication
customization.
mechanism
• Speech tobetween
text. two computers using
TCP/IP.
Socket
FROYO ANDROID 2.2 API LEVEL 8

• Released on May 20, 2010.


• Voice action.
❑ Network socket is an endpoint of an inter-
process
• USB communication
tethering and Potable flow across a
computer network.
hotspot.
• Speed, memory, and
❑ Sockets provide the communication
performance
mechanism between two computers using
optimizations
TCP/IP.
Socket
GINGERBREAD ANDROID 2.3 – 2.3.3 API LEVEL 9 -10

• Released on December
❑ Network socket is an endpoint of an inter-
6, 2010.
•process
Support forcommunication
multiple flow across a
computer network.
cameras.
• Gaming APIs, NFC.
❑ Sockets provide the communication
• Battery management
mechanism between two computers using
TCP/IP.
HONEYCOMB ANDROID 3.0, 3.1, 3.2
Socket
API LEVEL 11, 12, 13

• Released in February
❑ Network socket is an endpoint of an inter-
22, 2011.
process
• Tablet communication
friendly design. flow across a
computer network.
• System bar.
• Quick settings.
❑ Sockets provide the communication
mechanism between two computers using
TCP/IP.
ICE-CREAM SANDWICH ANDROID 4.0,4.0.3
Socket
API LEVEL 14,15

• Released on October 18,


❑ Network2011.
socket is an endpoint of an inter-
process communication
• Customize home screen. flow across a
computer network.
• Android beam.
• Data Usage
❑ Sockets provide
control.the communication
mechanism between two computers using
TCP/IP.
JELLY BEAN ANDROID 4.1-4.3
Socket
API LEVEL 16-18

• Released on July 9,
Network socket is an endpoint of an inter-
❑2012.
process communication
• Google Now. flow across a
computer network.
• Actionable notification.
❑ •Sockets provide
Switchable the communication
account.
mechanism between two computers using
TCP/IP.
KITKAT
Socket
ANDROID 4.4, 4.4.W API LEVEL 19, 20

• Released on October 31,


❑ Network2013.
socket is an endpoint of an inter-
process communication flow across a
• Ok Google.
computer network.
• Immersive design.
• Smartprovide
❑ Sockets Dialer the communication
mechanism between two computers using
TCP/IP.
LOLLIPOP ANDROID 5.0,5.1
Socket
API LEVEL 21,22

• Released on November
❑ Network socket is an endpoint of an inter-
12, 2014.
process
• Materialcommunication
Design. flow across a
computer network.
• Notification.
❑ Sockets provide the communication
• Multiscreen.
mechanism between two computers using
TCP/IP.
MARSHMALLOW ANDROID 6.0
Socket
API LEVEL 23

• Released on October 5,
❑ Network socket is an endpoint of an inter-
2015.
process
• Now communication
on tap. flow across a
computer network.
• Permission can be
turned off.
❑ Sockets provide the communication
• mechanism
Doze and appbetween
standby two computers using
TCP/IP.
for battery optimization.
NOUGAT ANDROID 7.0
Socket
API LEVEL 24

• Released on 22 August
❑ Network socket is an endpoint of an inter-
2016.
process communication flow across a
• Multi window.
computer network.
• Notification sheets.
• Switch
❑ Sockets provide
apps the communication
by double
mechanism
tapping between two computers using
in overview
TCP/IP.
button.
Android 8.0 Oreo

Android Oreo was internally


codenamed "Oatmeal
Cookie." On March 21, 2017,
Google released the first
developer preview
of Android "O", available for
the Nexus 5X, Nexus 6P,
Nexus Player, Pixel C, and
both Pixel smart phones. The
second, considered beta
quality, was released on May
17, 2017.
Android 9 (pie)

•Android Pie, then referred to


as "Android P", was first
announced by Google on
March 7, 2018, and the first
developer preview was
released on the same day.
•The second preview,
considered beta quality, was
released on May 8, 2018.
•The third preview, called
Beta 2, was released on June
6, 2018.
Android 10

▪Google opted to drop the


tradition of naming the
Android version after sweets
and desserts. It was launched
in September 3, 2019.
▪A number of features were
added such as support for the
upcoming foldable smart
phones with flexible displays.
▪ It newly
introduced navigation control
using gestures.
ANDROID ECOSYSTEM

• Android ecosystem is inter-dependence between


users, developer, and equipment makers.
• One can not exist without the other.
• Building block of Android ecosystem
1.Android User
2.Equipment maker for Android devices
3.Developer
ANDROID ECOSYSTEM

1. Android User:

- Android user has more space for customizability


their devices.
- Android user can easily download android apps
from Google Play store and can access easily.
- Android user is saving cost for their android
devices.
ANDROID ECOSYSTEM

2. Equipment maker for Android devices:

There are now more than 24,000 different android


devices.
ANDROID ECOSYSTEM

SMARTWATCHES
ANDROID ECOSYSTEM

MOBILE PHONES
ANDROID ECOSYSTEM

ANDROID TABLETS
ANDROID ECOSYSTEM

SMART TVs
ANDROID ECOSYSTEM

SMART GLASSES
ANDROID ECOSYSTEM

HOME APPLIANCES
ANDROID ECOSYSTEM

3. Developer :
• Android developer is specialist software developer in designing
application for android.
• Design and build advanced application for the android platform.
• Collaborate and define with development teams for design new
feature.
• Troubleshoot and fix bugs in new and existing applications.
• Evaluate and implement new development tools work with
outside data sources and API’s.
Need of Android

1. Android Market
2. Customization
3. Rooting
4. The Android Community
5. Powerful Development Framework
6. Global Partnerships and large installed base
FEATURES OF ANDROID

Sr.No. Feature & Description

1 Beautiful UI
Android OS basic screen provides a beautiful and intuitive user interface.

2 Connectivity
GSM/EDGE, IDEN, CDMA, EV-DO, UMTS, Bluetooth, Wi-Fi, LTE, NFC
and WiMAX.

3 Storage
SQLite, a lightweight relational database, is used for data storage purposes.

4 Media support
H.263, H.264, MPEG-4 SP, AMR, AMR-WB, AAC, HE-AAC, AAC 5.1,
MP3, MIDI, Ogg Vorbis, WAV, JPEG, PNG, GIF, and BMP.
FEATURES OF ANDROID

Sr.No. Feature & Description


5 Messaging : SMS and MMS

6 Web browser
Based on the open-source WebKit layout engine, coupled with Chrome's V8
JavaScript engine supporting HTML5 and CSS3.
7 Multi-touch
Android has native support for multi-touch which was initially made
available in handsets such as the HTC Hero.
8 Multi-tasking
User can jump from one task to another and same time various application
can run simultaneously.
9 Resizable widgets
Widgets are resizable, so users can expand them to show more content or
shrink them to save space.
FEATURES OF ANDROID

Sr.No. Feature & Description


10 Multi-Language
Supports single direction and bi-directional text.
11 GCM
Google Cloud Messaging (GCM) is a service that lets developers send
short message data to their users on Android devices, without needing a
proprietary sync solution.
12 Wi-Fi Direct
A technology that lets apps discover and pair directly, over a high-
bandwidth peer-to-peer connection.
13 Android Beam
A popular NFC-based technology that lets users instantly share, just by
touching two NFC-enabled phones together.
FEATURES OF ANDROID

Android can run multiple apps at the same time


Also support optimized graphics VGA,
2D graphics and 3D graphics.
Android has better app market.
Android lets you change your setting faster.
It gives you more options to fit your budget
Android keeps information visible on your
home screen.
Android also support java applications.
ANDROID ARCHITECTURE
ANDROID ARCHITECTURE

❖ Application
• Android will ship with a set of core applications including an
email client, SMS program, calendar, maps, browser,
contacts, and others. All applications are written using the Java
programming language.
ANDROID ARCHITECTURE

❖ Application Framework
• The application framework provides the classes used to create
Android applications. It also provides a generic abstraction
for hardware access and manages the user interface and
application resources.
ANDROID ARCHITECTURE

❖ Libraries
• On the top of Linux kernal.
• Webkit library used for browser support.
• FreeType for Font support.
• SQLite for database support.
ANDROID ARCHITECTURE

❖ Android Runtime
• Android includes a set of core libraries that provides most of the
functionality available in the core libraries of the Java programming
language.
• Every Android application runs in its own process, with its own
instance of the Dalvik virtual machine.
• Dalvik has been written so that a device can run multiple VMs
efficiently.
ANDROID ARCHITECTURE

❖ Linux Kernel
• It is core of android OS that exists at the root of android
architecture.
• It is responsible for device driver, power management,
memory management, device management and resource
access.
SOFTWARE FEATURES

OS:
1. Microsoft Windows version
2. Mac OS
3. Linux including GNU C Libraray.

Software:
1. JDK
2. Android Studio
SOFTWARE FEATURES

➢ Integrated browser based on the open source


Web Kit engine.
➢ SQLite for relational data storage.
➢ Media support for common audio, video, and
still image formats.
➢ Dalvik Virtual Machine optimized for
mobile devices.
HARDWARE FEATURES

➢Cellularnetworking : GSM, EDGE, 3G


➢LAN : Bluetooth, and Wi-Fi
➢Graphics Hardware Acceleration
➢Camera, GPS and Compass
➢Touch screen and accelerometer for
motion sensing
Android Advantages and Disadvantages

• Advantages:
1. Multitasking
2. Easy of Notifications
3. Easy access to thousands of applications via the Google
Android Android App Market
4. Can install a modified ROM
5. Widget
6. Voice typing and actions
7. Support VGA,2D & 3D.

• Disadvantages:
1. Continuous Internet connection
2. Advertising
Socket
Thank You
❑ Network socket is an endpoint of an inter-
process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Chapter
Unit II 04
Installation and Configuration
Networking
of Android and Security
Hours: 06 Marks: 06

Presented by:

Prof.S.S.Bhosale
Pravara Polytechnic Loni
Socket
Specific Objective

Configure Android environment and


❑ Network socket is an endpoint of an inter-
development tools.
process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
Operating System

• The operating system is the most important


❑ Network
program socket is an
that runs onendpoint of an inter-
a computer.
• process communication flow across a
Operating system is an interface between
computer network.
computer and user.
• Sockets
❑ It is responsible
provide thefor the management and
communication
mechanism between
coordination two computers
of activities and the using
sharing of
TCP/IP.
the resources of the computer.
Socket
Operating System

• An Operating system (OS) is system software


❑ Network socketcomputer
that manages is an endpoint of an inter-
hardware ,software
process communication
recourses and provideflow acrossservices
common a for
computer network.
common program.
• Sockets
❑ An OS isprovide thethat
software communication
manages the computer
mechanism
hardware. between two computers using
TCP/IP.
• An OS can System software which provide
environment for execution of program.
Socket
Operating System

❑ Network socket is an endpoint of an inter-


process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
Types of Operating System

1. Batch Operating System


❑ Network socket is an endpoint of an inter-

2.process communication flow across a


Time Sharing Operating System.
computer network.
3. Distributed Operating System.
❑ Sockets provide the communication
4.mechanism between two
Network Operating computers using
System
TCP/IP.
5. Real- Time Operating System
Socket
1. Batch Operating System :
- This type of OS does not interact with the computer
❑ Network
directly. socket is an endpoint of an inter-
-process
There is ancommunication
operator whichflow
takesacross
similar ajobs
computer
having samenetwork.
requirement and group them into
batches.
❑ Sockets provide the
- It is responsibility communication
of operator to sort the jobs
mechanism between two computers using
with similar needs.
TCP/IP.
eg. Payroll System, Bank Statements.
Socket
2.Time Sharing Operating System:
- Each task is given some time to execute, so that all task
work smoothly.
❑ Network socket is an endpoint of an inter-
process
- Each communication
user gets time of CPU asflow
they across
use singlea System.
computer
- These systemnetwork.
also known as Multitasking system.
- The time that each task gets to execute is called
❑ Sockets provide the communication
mechanism
quantum. between two computers using
TCP/IP.
- After this time interval is over OS switches over to next
task.
Socket
3. Distributed Operating System:
- A distributed operating system is system software
over a collection of independent, networked,
❑ Network socket is an endpoint of an inter-
process communication
communicating, flowseparate
and physically across a
computer network.
computational nodes.

❑-Sockets provide
They handle the communication
jobs which are serviced by multiple
mechanism between node
CPUs. Each individual two holds
computers using
a specific
TCP/IP.
software subset of the global aggregate operating
system.
- Remote access is enable by using distributed OS.
Socket
4. Network Operating System:

- These systems runs on a server and provide the


❑ Network socket
capability to isdata,
manage an endpoint of an
users, group, inter-
security,
process communication flow across a
computer
application,network.
and other networking functions.
- These type of OS allows share access of files,
❑ Sockets provide the communication
printers, security, application, and other networking
mechanism between two computers using
TCP/IP.
functions over a small private network.
- eg. Windows server 2003, 2008, Unix, Linux, Mac
OS, Novell Netware etc.
Socket
5. Real-Time Operating System:

- The time interval required to process and respond to


❑ Network socket
input is very is real
small in an endpoint
time OS. of an inter-
process communication flow across a
- computer network.
Time interval called as response time.
- Real time OS used when there are time requirements
❑ Sockets provide the communication
are very strict like missile systems, air traffic
mechanism between two computers using
TCP/IP.
control, robots etc.
1. Hard real- time System
2. Soft real- time System.
Socket
2.1.2 Java JDK

1. JVM:
❑ Network socket
Java Virtual is an endpoint of an inter-
Machine
process communication flow across a
2.computer
JRE network.
Java Runtime Environment
❑ Sockets provide the communication
3. JDK
mechanism between two computers using
TCP/IP.
Java development Kit
Socket
2.1.2.1 Working of JVM

❑ Network socket is an endpoint of an inter-


process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
2.1.2.1 Working of JVM

❑ Network socket is an endpoint of an inter-


process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
2.1.3 Android SDK

- Android SDK is software development kit that


❑ Network socket is to
enables developers ancreate
endpoint of an inter-
applications for the
process communication flow across a
computer network.
android platform.
- It includes the complete set of development and
❑ Sockets provide the communication
debugging tools
mechanism for android
between .
two computers using
- TCP/IP.
It is included with Android studio.
Socket
2.1.3 Android SDK

- It includes Sample project with source code,


❑ Network socket
development tools,isananemulator,
endpoint andof an inter-
required
process communication flow across a
computer network.
library to build android application.
- Application written using java programming
❑ Sockets provide the communication
language and runs on Dalvik virtual machine.
mechanism between two computers using
- TCP/IP.
DVM is designed for embedded use which runs on
top of Linux kernal.
Socket
2.1.3 Android SDK

Android SDK include following:


❑ Network socket is an endpoint of an inter-
process communication flow across a
1.computer network.
Required library
2. Debugger
❑ Sockets provide the communication
3. An emulator
mechanism between two computers using
4.TCP/IP.
Sample source code
5. Tutorial for Android OS.
6. Relevant document for Android API.
Socket
2.2 Android Development Tools

1. Android Studio
❑ Network socket is an endpoint of an inter-
2.process communication
Visual Studio flow across a
with Xamarin
computer network.
3. Eclipse
❑ Sockets provide the communication
mechanism between two computers using
TCP/IP.
Socket
2.3 Android Virtual Devices
- Android Virtual device (AVD) is configuration

❑ Network
that definessocket is an endpoint
the characteristics of an inter-
of an android phone,
process communication
tablet, android flowtoacross
TV that you want a in
simulate
computer network.
android emulator.

❑ Sockets provide the communication


mechanism between
- The AVD manager is antwo computers
interface using
launch from
TCP/IP.
android studio that helps you create and manage
AVD’s.
Socket
2.3 Android Virtual Devices

- The AVD is a device configuration that is run with the


❑ Network socket is an endpoint of an inter-
android emulator.
process communication flow across a
-computer network.
It works with emulator to provide virtual device
specific environment to install and run android apps.
❑ Sockets provide the communication
Tomechanism between
open the AVD Manager,two computers
do one using
of the following:
TCP/IP.
Select Tools > AVD Manager.

Click AVD Manager in the toolbar


Socket
2.3 Android Virtual Devices

❑ Network socket is an endpoint of an inter-


process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
2.3 Android Virtual Devices

❑ Network socket is an endpoint of an inter-


process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
2.3 Android Virtual Devices

❑ Network socket is an endpoint of an inter-


process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
2.3 Android Virtual Devices

❑ Network socket is an endpoint of an inter-


process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
2.3 Android Virtual Devices

❑ Network socket is an endpoint of an inter-


process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
2.3 Android Virtual Devices

❑ Network socket is an endpoint of an inter-


process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
2.4 Android Emulator

• The Android SDK includes a mobile device


Network
❑emulator - a socket is an endpoint
virtual mobile device thatofruns
an inter-
on your
process communication flow across a
computer.
computer network.
• The emulator lets you prototype, develop, and test
Android applications without using a physical
❑ Sockets provide the communication
device.
mechanism between two computers using
TCP/IP.
• The Android emulator mimics all of the hardware and
software features of a typical mobile device, except
that it can not receive or place actual phone calls.
Socket
2.4 Android Emulator

• ❑ItNetwork
provides asocket is navigation
variety of an endpointandof an inter-
control keys,
process
which communication
you can "press" usingflow
your across
mouse ora keyboard
tocomputer network.
generate events for your application.

• It also provides a screen in which your application is


❑ Sockets provide the communication
displayed, together with any other Android
mechanism between two computers using
applications running.
TCP/IP.
Socket
2.4 Android Emulator

❑ Network socket is an endpoint of an inter-


process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
2.5 Dalvik Virtual Machine (DVM)

• The Dalvik Virtual Machine (DVM) is an android


❑ Network socket is an endpoint of an inter-
process
virtual communication
machine optimized forflow across
mobile a
devices.
computer network.
• Dalvik is a town in Iceland.
❑ Sockets provide the communication
mechanism
• The Dalvik VMbetween twobycomputers
was written using
Den Bornstein.
TCP/IP.
• The DEX compiler converts the .class file into .dex

file that runs on Dalvik VM.


Socket
2.5 Dalvik Virtual Machine (DVM)

• Multiple class files are converted into one dex file.


❑ Network socket is an endpoint of an inter-
process
• The DVM is communication
a virtual machineflow
to across a
computer network.
run Android applications.
❑ Sockets provide the communication
mechanism
• The between
DVM executes Dalviktwo computers
bytecode, whichusing
is
TCP/IP.
compiled from programs written in the Java language
Socket
2.5 Working of DVM

❑ Network socket is an endpoint of an inter-


process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
2.5.2 Difference between DVM and JVM

❑ Network socket is an endpoint of an inter-


process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
2.5.2 Difference between DVM and JVM

Sr.No JVM(Java Virtual Machine) DVM(Dalvik Virtual Machine)

❑ Network
logic operations socket
through push is
and an endpoint oflocated
an ininter-
Stack-based VM that performs arithmetic and Register-based VM that uses
pop operands. registers the CPU to
process communication
is stored in stack flowperform
across a
1
The result of operations arithmetic and logic
memory. operations.
computer network.
Source code files are first of all
compiled into Java bytecode

❑ Sockets provide the communication


format like JVM. Further,
Java source code is compiled into Java bytecode
the DEX compiler(dx
mechanism between two computers using
2 format(.class file) that further translates into
tool) converts the Java bytecode
machine code.
into Dalvik bytecode(classes.dex)
TCP/IP. file that will be used to create
the .apk file.
More information is required to the VM for data Instruction size is larger as it needs
3 loading and manipulation as well as method to encode the source and
loading in the stack data structure. destination register of the VM.
Socket
2.5.2 Difference between DVM and JVM

Compiled bytecode size is compact because the Compiled bytecode size is larger
4 location of the operand is implicitly on the as each instruction needs all
❑ Network socket is an endpoint of an inter-
operand stack. implicit operands.

process communication flow across a


computer network.
The executable file for the device
5 The executable file for the device is .jar file.
is .apk file.

❑ Sockets provide the communication


The device runs multiple DVM
6
mechanism between two computers
A single instance of JVM is configured with
shared processes and memory space in order to
using
instances with a separate process
TCP/IP.
run all deployed applications.
in shared memory space to deploy
the code of each application.

Supports multiple operating systems like Linux, Support only the Android
7
Windows, and Mac OS. operation system.
Socket
2.6 Steps to install and configure Android Studio and SDK

After downloading the android-studio-ide-


❑ Network socket is anfile,
171.4443003-windows.exe endpoint of an inter-
process
follow communication
the below flow across a
steps to install.
computer network.
Step – 1 : Right click on downloaded .exe file and Run
as Administrator.
❑ Sockets provide the communication
mechanism between two computers using
Step – 2 : You will see the below Setup wizard.
TCP/IP.
Socket
2.6 Steps to install and configure Android Studio and SDK

Step 1:

❑ Network socket is an endpoint of an inter-


process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
2.6 Steps to install and configure Android Studio and SDK

Step 2:

❑ Network socket is an endpoint of an inter-


process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
2.6 Steps to install and configure Android Studio and SDK

Step 3:

❑ Network socket is an endpoint of an inter-


process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
2.6 Steps to install and configure Android Studio and SDK

Step 4:

❑ Network socket is an endpoint of an inter-


process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
2.6 Steps to install and configure Android Studio and SDK

Step 5:

❑ Network socket is an endpoint of an inter-


process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
2.6 Steps to install and configure Android Studio and SDK

Step 6:

❑ Network socket is an endpoint of an inter-


process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
2.6 Steps to install and configure Android Studio and SDK

Step – 7:
Here is the Welcome Screen.

❑ Network socket is an endpoint of an inter-


process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
2.6 Steps to install and configure Android Studio and SDK

Step – 8:
Here click on Standard option

❑ Network socket is an endpoint of an inter-


process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
2.6 Steps to install and configure Android Studio and SDK

Step – 9:
It will ask for the UI Theme, by default it would be IntelliJ, then directly you can click
on Next.
❑ Network socket is an endpoint of an inter-
process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
2.6 Steps to install and configure Android Studio and SDK

Step – 10:
It will ask for the confirmation for installation setting wizard.

❑ Network socket is an endpoint of an inter-


process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
2.6 Steps to install and configure Android Studio and SDK

Step – 11:
It will download all necessary components to launch the Android Studio and setting up
the environment
❑ Network socket is an endpoint of an inter-
process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Socket
Thank You
❑ Network socket is an endpoint of an inter-
process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.
Chapter
Unit III 04

UI Components
Networking andand Layouts
Security
Hours: 08 Marks: 08

Presented by:

Prof. S.S.Bhosale
Pravara Polytechnic, Loni
Socket
Specific Objective

Develop rich user Interfaces by using layouts


 Network
and socket is an endpoint of an inter-
controls.
process communication flow across a
computer network.

 Sockets provide the communication


mechanism between two computers using
TCP/IP.
Control Flow

-Java programming language can be used to


development of Android apps.

-Android IDE or tools check and compile the


dependancies , code, resources, data and generate
APK.

-APK having all content of app.

-Each app runs on emulator.


Control Flow

Application components are the essential building


blocks of an Android application.

These components are loosely coupled by the


application manifest file AndroidManifest.xml that
describes each component of the application and how
they interact.

There are following four main components that can be


used within an Android application .
Control Flow
Sr. No Components & Description
Activities
1 They dictate the UI and handle the user interaction to the
smart phone screen.
Services
2 They handle background processing associated with an
application.
Broadcast Receivers
3 They handle communication between Android OS and
applications.
Content Providers
4 They handle data and database management issues.
Control Flow

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.
Control Flow

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 {


}
Control Flow

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 { }
Control Flow

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.
Control Flow

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)
{
}
}
Control Flow
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.
Control Flow
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.

eg.
public class MyContentProvider extends ContentProvider
{
public void onCreate()
{}
}
Control Flow
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.

eg.
public class MyContentProvider extends ContentProvider
{
public void onCreate()
{}
}
3.1.1 Additional Components :

S.No Components & Description


Fragments
1 Represents a portion of user interface in an Activity.
Views
2 UI elements that are drawn on-screen including buttons, lists forms etc.
Layouts
3 View hierarchies that control screen format and appearance of the views.
Intents
4 Messages wiring components together.
Resources
5 External elements, such as strings, constants and drawable pictures.
Manifest
6 Configuration file for the application.
3.1.2 Android Application Structure :
3.1.2 Android Application Structure :

Sr.No. Folder, File & Description


Java
This contains the .java source files for your project. By
1 default, it includes an MainActivity.java source file having an
activity class that runs when your app is launched using the
app icon.
res/drawable-hdpi
2 This is a directory for drawable objects that are designed for
high-density screens.
res/layout
3 This is a directory for files that define your app's user
interface.
3.1.2 Android Application Structure :

Sr.No. Folder, File & Description


res/values
4 This is a directory for other various XML files that contain a
collection of resources, such as strings and colours definitions.
AndroidManifest.xml
5 This is the manifest file which describes the fundamental
characteristics of the app and defines each of its components.
Build.gradle
This is an auto generated file which contains
6 compileSdkVersion, buildToolsVersion, applicationId,
minSdkVersion, targetSdkVersion, versionCode and
versionName
3.1.2 .1 The Main Activity File

The main activity code is a Java file MainActivity.java.

This is the actual application file which ultimately gets converted to


a Dalvik executable and runs your application.

Following is the default code generated by the application wizard


for Hello World! application −
3.1.2 .1 The Main Activity File

eg.

package com.example.helloworld;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
3.1.2 .1 The Main Activity File

Here, R.layout.activity_main refers to


the activity_main.xml file located in the res/layout folder.

The onCreate() method is one of many methods that are


figured when an activity is loaded.
3.1.2 .2 The Manifest File

Whatever component you develop as a part of your


application, you must declare all its components in
a manifest.xml which resides at the root of the application
project directory.

This file works as an interface between Android OS and


your application, so if you do not declare your component
in this file, then it will not be considered by the OS.
3.1.2 .2 The Manifest File

For example, a default manifest file will look like as following file :

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.firstapplication">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
</application>

</manifest>
3.1.2 .2 The Manifest File

Here <application>...</application> tags enclosed the


components related to the application.

Attribute android:icon will point to the application icon


available under res/drawable-hdpi.

The application uses the image named ic_launcher.png


located in the drawable folders
3.1.2 .2 The Manifest File

The <activity> tag is used to specify an activity


and android:name attribute specifies the fully qualified
class name of the Activity subclass and
the android:label attributes specifies a string to use as the
label for the activity.
You can specify multiple activities using <activity> tags.
3.1.2 .2 The Manifest File

The action for the intent filter is


named android.intent.action.MAIN to indicate that this
activity serves as the entry point for the application.
The category for the intent-filter is
named android.intent.category.LAUNCHER to indicate
that the application can be launched from the device's
launcher icon.
3.1.2 .3 The Strings File

The strings.xml file is located in the res/values folder and


it contains all the text that your application uses.

For example, the names of buttons, labels, default text,


and similar types of strings go into this file.

This file is responsible for their textual content.


3.1.2 .3 The Strings File

<resources>
<string
name="app_name">HelloWorld</string> <string
name="hello_world">Hello world!</string> <string
name="menu_settings">Settings</string> <string
name="title_activity_main">MainActivity
</string>
</resources>
3.1.2 .4 The Layout File

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.
3.1.2 .4 The Layout File

<RelativeLayout 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" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:layout_centerVertical="true"
android:padding="@dimen/padding_medium"
android:text="@string/hello_world"
tools:context=".MainActivity" />
</RelativeLayout>
3.1.3 Android UI Controls

Sr.No UI Control & Description


1 TextView

This control is used to display text to the user.


2 EditText
EditText is a predefined subclass of TextView that includes rich
editing capabilities.
3 AutoCompleteTextView
The AutoCompleteTextView is a view that is similar to EditText,
except that it shows a list of completion suggestions automatically
while the user is typing.
4 Button
A push-button that can be pressed, or clicked, by the user to
perform an action.
3.1.3 Android UI Controls

Sr.No UI Control & Description


5 ImageButton
An ImageButton is an AbsoluteLayout which enables you to specify the
exact location of its children. This shows a button with an image (instead of
text) that can be pressed or clicked by the user.
6 Checkbox
An on/off switch that can be toggled by the user. You should use check box
when presenting users with a group of selectable options that are not
mutually exclusive.
7 ToggleButton
An on/off button with a light indicator.
8 RadioButton
The RadioButton has two states: either checked or unchecked.
9 RadioGroup
A RadioGroup is used to group together one or more RadioButtons.
3.1.3 Android UI Controls

Sr.No UI Control & Description


10 ProgressBar
The ProgressBar view provides visual feedback about some
ongoing tasks, such as when you are performing a task in the
background.
11 Spinner
A drop-down list that allows users to select one value from a set.
12 TimePicker
The TimePicker view enables users to select a time of the day, in
either 24-hour mode or AM/PM mode.
13 DatePicker
The DatePicker view enables users to select a date of the day.
3.1.4 Create UI Controls

- Input controls are the interactive components in


your app's user interface.

- Android provides a wide variety of controls you


can use in your UI, such as buttons, text fields,
seek bars, check box, zoom buttons, toggle
buttons, and many more.
3.1.4 Create UI Controls

A view object may have a unique ID assigned to


it which will identify the View uniquely within
the tree.
The syntax for an ID

android:id="@+id/id_text“/>
3.1.4 Create UI Controls

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/text_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content“
android:text="I am a TextView" />
</LinearLayout>
3.1.4 Create UI Controls

Then finally create an instance of the Control object and


capture it from the layout, use the following

TextView t1= (TextView) findViewById(R.id.text_id);

<Button
android:id=“@+id/b1”
/>

Button b1=(Button) findViewById(R.id.b1);


3.3 Types of Layout

1. Linear Layout
2. Absolute Layout
3. Table Layout
4. Frame Layout
5. Relative Layout
6. Constraints Layout
3.3.1 Linear Layout

• Linear Layout further divided into horizontal and vertical


layout.

• In this we can arrange components in single column or single


row.
3.3.1 Linear Layout

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a TextView" />
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a Button" />
</LinearLayout>
3.3.1 Linear Layout Attribute

Sr.No Attribute & Description


1 android:id
This is the ID which uniquely identifies the view.
2 android:layout_width
This is the width of the layout.
3 android:layout_height
This is the height of the layout
3.3.1 Linear Layout Attribute

Sr.No Attribute & Description


4 android:layout_gravity
This specifies how child Views are positioned.
5 Android:orientation
This specifies the direction of arrangement and you will use
horizontal for row and vertical for coloumn . The default is
horizontal.
3.3.2 Absolute Layout

The Absolute Layout enables you to specify the exact


location of its children. It can be declared

<AbsoluteLayout
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
xmlns:android=”http://schemas.android.com/apk/res/android” >
<Button
android:layout_width=”188dp”
android:layout_height=”wrap_content”
android:text=”Button”
android:layout_x=”126px”
android:layout_y=”361px” />
</AbsoluteLayout>
3.3.2 Absolute Layout

The Absolute Layout lets you to specify exact


locations (x/y coordinates) of its children
Absolute Layouts are less flexible and harder to
maintain than other layouts.

(25,30)
(100,70)

(15,180)
3.3.2 Absolute Layout

Sr.No Attribute & Description


1 android:id

This is the ID which uniquely identifies the view.

2 android:layout_x
This specifies the x-coordinate of the view.
3 android:layout_y
This specifies the y-coordinate of the view.
4 android:layout_width
This is the width of the layout.
5 android:layout_height
This is the height of the layout
3.3.3 Table Layout

Android TableLayout going to be arranged groups of views


into rows and columns.

You will use the <TableRow> element to build a row in the


table. Each row has zero or more cells; each cell can hold
one View object.

TableLayout containers do not display border lines for their


rows, columns, or cells.
3.3.3 Table Layout
3.3.3 Table Layout Attribute

Sr.No. Attribute & Description


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

2 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.
3 android:shrinkColumns
The zero-based index of the columns to shrink. The column indices
must be separated by a comma: 1, 2, 5.
4 android:stretchColumns
The zero-based index of the columns to stretch. The column indices
must be separated by a comma: 1, 2, 5.
3.3.3 Relative Layout

 Android Relative Layout enables you to


specify how child views are positioned
relative to each other.

 The position of each view can be


specified as relative to sibling elements or
relative to the parent.
3.3.3 Relative Layout
3.3.3 Relative Layout Attributes

Sr.No. Attribute & Description


1 android:id
This is the ID which uniquely identifies the layout.
2 android:gravity
This specifies how an object should position its
content, on both the X and Y axes. Possible values are
top, bottom, left, right, center, center_vertical,
center_horizontal etc.
3 android:ignoreGravity
This indicates what view should not be affected by
gravity.
3.3.3 Relative Layout Attributes

Sr.No. Attribute & Description


1 android:layout_above
Positions the bottom edge of this view above the given anchor view
ID and must be a reference to another resource, in the form
"@[+][package:]type:name"
2 android:layout_alignBottom
Makes the bottom edge of this view match the bottom edge of the
given anchor view ID and must be a reference to another resource, in
the form "@[+][package:]type:name".
3 android:layout_alignLeft
Makes the left edge of this view match the left edge of the given
anchor view ID and must be a reference to another resource, in the
form "@[+][package:]type:name".
3.3.3 Relative Layout Attributes

4 android:layout_alignParentBottom
If true, makes the bottom edge of this view match the
bottom edge of the parent. Must be a boolean value, either
"true" or "false".
5 android:layout_alignParentEnd
If true, makes the end edge of this view match the end
edge of the parent. Must be a boolean value, either "true"
or "false".
6 android:layout_alignParentLeft
If true, makes the left edge of this view match the left edge
of the parent. Must be a boolean value, either "true" or
"false".
3.3.3 Relative Layout Attributes

7 android:layout_alignParentRight
If true, makes the right edge of this view match the right edge
of the parent. Must be a boolean value, either "true" or "false".

8 android:layout_alignParentStart
If true, makes the start edge of this view match the start edge of
the parent. Must be a boolean value, either "true" or "false".

9 android:layout_alignParentTop
If true, makes the top edge of this view match the top edge of
the parent. Must be a boolean value, either "true" or "false".
3.3.3 Relative Layout Attributes

10 android:layout_alignRight
Makes the right edge of this view match the right edge of the
given anchor view ID and must be a reference to another
resource, in the form "@[+][package:]type:name".
11 android:layout_alignStart
Makes the start edge of this view match the start edge of the
given anchor view ID and must be a reference to another
resource, in the form "@[+][package:]type:name".
12 android:layout_alignTop
Makes the top edge of this view match the top edge of the
given anchor view ID and must be a reference to another
resource, in the form "@[+][package:]type:name".
3.3.3 Relative Layout Attributes

13 android:layout_below
Positions the top edge of this view below the given anchor view
ID and must be a reference to another resource, in the form
"@[+][package:]type:name".
14 android:layout_centerHorizontal
If true, centers this child horizontally within its parent. Must be
a boolean value, either "true" or "false".

15 android:layout_centerInParent
If true, centers this child horizontally and vertically within its
parent. Must be a boolean value, either "true" or "false".
3.3.3 Relative Layout Attributes

16 android:layout_centerVertical
If true, centers this child vertically within its parent. Must be
a boolean value, either "true" or "false".
17 android:layout_toEndOf
Positions the start edge of this view to the end of the given
anchor view ID and must be a reference to another resource,
in the form "@[+][package:]type:name".
18 android:layout_toLeftOf
Positions the right edge of this view to the left of the given
anchor view ID and must be a reference to another resource,
in the form "@[+][package:]type:name".
3.3.3 Relative Layout Attributes

19 android:layout_toRightOf
Positions the left edge of this view to the right of the given
anchor view ID and must be a reference to another resource,
in the form "@[+][package:]type:name".
20 android:layout_toStartOf
Positions the end edge of this view to the start of the given
anchor view ID and must be a reference to another resource,
in the form "@[+][package:]type:name".
3.3.4 Frame Layout

Frame Layout is designed to block out an area on


the screen to display a single item.

FrameLayout should be used to hold a single


child view, because it can be difficult to organize
child views in a way that's scalable to different
screen sizes without the children overlapping each
other.
3.3.4 Frame Layout

You can add multiple children to a FrameLayout


and control their position within the FrameLayout
by assigning gravity to each child, using the
android:layout_gravity attribute.
3.3.4 Frame Layout Attribute

Sr.No Attribute & Description


1 android:id

This is the ID which uniquely identifies the layout.

2 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".

3 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.
4 android:measureAllChildren

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


INVISIBLE state when measuring. Defaults to false.
Socket
Thank You
 Network socket is an endpoint of an inter-
process communication flow across a
computer network.

 Sockets provide the communication


mechanism between two computers using
TCP/IP.
Chapter
Unit IV 04

Networking and Security


Designing User Interface with View

Hours: 10 Marks: 12

Presented by:

Prof. S.S.Bhosale
Pravara Polytechnic, Loni
Specific Objective

Use User Interface components for


android application development.
4.1 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.
4.1.1 TextView Attributes

Sr.No. Attribute & Description


1 android:id
This is the ID which uniquely identifies the control.

2 android:capitalize
If set, specifies that this TextView has a textual input method and
should automatically capitalize what the user types.
 Don't automatically capitalize anything - 0
 Capitalize the first word of each sentence - 1
 Capitalize the first letter of every word - 2
 Capitalize every character - 3
3 android:cursorVisible
Makes the cursor visible (the default) or invisible. Default is false.
4.1.1 TextView Attributes

Sr.No. Attribute & Description


4 android:editable

If set to true, specifies that this TextView has an input method.


5 android:fontFamily

Font family (named by string) for the text.


6 android:gravity

Specifies how to align the text by the view's x- and/or y-axis when the text is
smaller than the view.
7 android:hint

Hint text to display when the text is empty.


8 android:inputType

The type of data being placed in a text field. Phone, Date, Time, Number,
Password etc.
4.1.1 TextView Attributes

Sr.No. Attribute & Description


9 android:maxHeight

Makes the TextView be at most this many pixels tall.


10 android:maxWidth

Makes the TextView be at most this many pixels wide.


11 android:minHeight

Makes the TextView be at least this many pixels tall.

12 android:minWidth

Makes the TextView be at least this many pixels wide.


13 android:password

Whether the characters of the field are displayed as password dots instead of
themselves. Possible value either "true" or "false".
4.1.1 TextView Attributes

Sr.No. Attribute & Description


14 android:phoneNumber

If set, specifies that this TextView has a phone number input method. Possible
value either "true" or "false".
15 android:text Text to display.

16 android:textAllCaps

Present the text in ALL CAPS. Possible value either "true" or "false".
17 android:textColor

Text color. May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or
"#aarrggbb".
18 android:textColorHighlight

Color of the text selection highlight.


4.1.1 TextView Attributes

Sr.No. Attribute & Description


19 android:textColorHint
Color of the hint text. May be a color value, in the form of "#rgb",
"#argb", "#rrggbb", or "#aarrggbb".
20 android:textIsSelectable
Indicates that the content of a non-editable text can be selected.
Possible value either "true" or "false".
21 android:textSize
Size of the text. Recommended dimension type for text is "sp" for
scaled-pixels (example: 15sp).
4.1.1 TextView Attributes

Sr.No. Attribute & Description


22 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
23 android:typeface

Typeface (normal, sans, serif, monospace) for the text. You can use or
more of the following values separated by '|'.
 normal - 0
 sans - 1
 serif - 2
 monospace – 3
4.2 EditText

A EditText is an overlay over TextView that configures itself


to be editable.

It is the predefined subclass of TextView that includes rich


editing capabilities.
4.2.1 EditText Attributes

Sr.No. Attribute & Description


1 android:autoText

If set, specifies that this TextView has a textual input method and
automatically corrects some common spelling errors.
2 android:drawableBottom

This is the drawable to be drawn below the text.


3 android:drawableRight

This is the drawable to be drawn to the right of the text.


4 android:editable

If set, specifies that this TextView has an input method.

5 android:text

This is the Text to display.


4.2.1 EditText Attributes

Sr.No. Attribute & Description


6 android:background
This is a drawable to use as the background.

7 android:contentDescription
This defines text that briefly describes content of the view.

8 android:id
This supplies an identifier name for this view.

9 android:onClick
This is the name of the method in this View's context to invoke when the
view is clicked.
10 android:visibility
This controls the initial visibility of the view.
4.3 AutoCompleteTextView

AutoCompleteTextView is a view that is similar


to EditText, except that it shows a list of
completion suggestions automatically while the
user is typing.

The list of suggestions is displayed in drop down


menu. The user can choose an item from there to
replace the content of edit box with.
4.3.1 AutoCompleteTextView Attributes
Sr.No. Attribute & Description

android:completionHint
1
This defines the hint displayed in the drop down menu.

android:completionHintView
2
This defines the hint view displayed in the drop down menu.
android:completionThreshold
3 This defines the number of characters that the user must type before
completion suggestions are displayed in a drop down menu.
android:dropDownAnchor
4
This is the View to anchor the auto-complete dropdown to.
android:dropDownHeight
5
This specifies the basic height of the dropdown.
4.3.1 AutoCompleteTextView Attributes
Sr.No. Attribute & Description

android:dropDownHorizontalOffset
6 The amount of pixels by which the drop down should be offset
horizontally.
android:dropDownSelector
7
This is the selector in a drop down list.
android:dropDownVerticalOffset
8
The amount of pixels by which the drop down should be offset vertically.

android:dropDownWidth
9
This specifies the basic width of the dropdown.
android:popupBackground
10
This sets the background.
4.4 Button

A Button is a Push-button which can be pressed, or


clicked, by the user to perform an action.
4.4 Button
Sr.No Attribute & Description
1 android:autoText

If set, specifies that this TextView has a textual input method and automatically
corrects some common spelling errors.
2 android:drawableBottom

This is the drawable to be drawn below the text.

3 android:drawableRight

This is the drawable to be drawn to the right of the text.

4 android:editable

If set, specifies that this TextView has an input method.

5 android:text

This is the Text to display.


4.4 Button
Inherited from android.view.View Class

Sr.No Attribute & Description


1 android:background

This is a drawable to use as the background.


2 android:contentDescription

This defines text that briefly describes content of the view.


3 android:id

This supplies an identifier name for this view.


4 android:onClick

This is the name of the method in this View's context to invoke when the view is
clicked.
5 android:visibility

This controls the initial visibility of the view.


4.5 ImageButton

An ImageButton is an AbsoluteLayout which enables you to


specify the exact location of its children.

This shows a button with an image (instead of text) that can be


pressed or clicked by the user.
4.5.1 ImageButton Attributes
Sr.No Attribute & Description
android:adjustViewBounds
1 Set this to true if you want the ImageView to adjust its bounds to preserve
the aspect ratio of its drawable.
android:baseline
2
This is the offset of the baseline within this view.
android:baselineAlignBottom
3 If true, the image view will be baseline aligned with based on its bottom
edge.
android:cropToPadding
4 If true, the image will be cropped to fit within its padding.

android:src
5
This sets a drawable as the content of this ImageView.
4.5.1 ImageButton Attributes
Inherited from android.view.View Class

Sr.No Attribute & Description


1 android:background

This is a drawable to use as the background.


2 android:contentDescription

This defines text that briefly describes content of the view.


3 android:id

This supplies an identifier name for this view.


4 android:onClick

This is the name of the method in this View's context to invoke when the view is
clicked.
5 android:visibility

This controls the initial visibility of the view.


4.6 ToggleButton

A ToggleButton displays checked/unchecked


states as a button.
It is basically an on/off button with a light
indicator.
4.6.1 ToggleButton Attributes

Sr.No Attribute & Description


1 android:disabledAlpha
This is the alpha to apply to the indicator when disabled.
2 android:textOff
This is the text for the button when it is not checked.
3 android:textOn
This is the text for the button when it is checked.
4.6.1 ToggleButton Attributes
Inherited from android.widget.TextView Class

Sr.No Attribute & Description


1 android:autoText
If set, specifies that this TextView has a textual input method and
automatically corrects some common spelling errors.
2 android:drawableBottom
This is the drawable to be drawn below the text.
3 android:drawableRight
This is the drawable to be drawn to the right of the text.
4 android:editable
If set, specifies that this TextView has an input method.

5 android:text
This is the Text to display.
4.6.1 ToggleButton Attributes
Inherited from android.view.View Class

Sr.No Attribute & Description


1 android:background

This is a drawable to use as the background.


2 android:contentDescription

This defines text that briefly describes content of the view.


3 android:id

This supplies an identifier name for this view.


4 android:onClick

This is the name of the method in this View's context to invoke when the view is
clicked.
5 android:visibility

This controls the initial visibility of the view.


4.7 RadioButton
A RadioButton has two states: either checked or
unchecked.

This allows the user to select one option from a set.


4.8 Radio Group

A RadioGroup class is used for set of radio buttons.

If we check one radio button that belongs to a radio


group, it automatically unchecks any previously
checked radio button within the same group.

Radio Group Attributes:

Attribute Description
android:checkedButton This is the id of child radio button that should be
checked by default within this radio group.
4.8.1 Radio Group
Inherited from android.view.View Class

Sr.No Attribute & Description


1 android:background

This is a drawable to use as the background.


2 android:contentDescription

This defines text that briefly describes content of the view.


3 android:id

This supplies an identifier name for this view.


4 android:onClick

This is the name of the method in this View's context to invoke when the view is
clicked.
5 android:visibility

This controls the initial visibility of the view.


4.9 CheckBox

A CheckBox is an on/off switch that can be toggled


by the user.

You should use check-boxes when presenting users


with a group of selectable options that are not
mutually exclusive.
4.9.1 CheckBox
Sr.No Attribute & Description
android:autoText
1 If set, specifies that this TextView has a textual input method and
automatically corrects some common spelling errors.
android:drawableBottom
2 This is the drawable to be drawn below the text.

android:drawableRight
3 This is the drawable to be drawn to the right of the text.

android:editable
4 If set, specifies that this TextView has an input method.

android:text
5 This is the Text to display.
4.9.1 CheckBox
Inherited from android.view.View Class
Sr.No Attribute & Description
1 android:background

This is a drawable to use as the background.


2 android:contentDescription

This defines text that briefly describes content of the view.


3 android:id

This supplies an identifier name for this view.


4 android:onClick

This is the name of the method in this View's context to invoke when the view is
clicked.
5 android:visibility

This controls the initial visibility of the view.


4.10 Progress Bars

- Progress bars are used to show progress of a task.

- For example, when you are uploading or


downloading something from the internet, it is better
to show the progress of download/upload to the user.

- In android there is a class called ProgressDialog that


allows you to create progress bar.

- In order to do this, you need to instantiate an object


of this class.
4.10 Progress Bars

Its syntax is:


ProgressDialog progress = new ProgressDialog(this);

Now you can set some properties of this dialog. Such as,
its style, its text etc.

progress.setMessage("Downloading Music :) ");


progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progress.setIndeterminate(true);
4.10 Progress Bars

Sr.No Attribute & Description


1 getMax()
This method returns the maximum value of the progress.
2 incrementProgressBy(int diff)
This method increments the progress bar by the difference of value passed
as a parameter.
3 setIndeterminate(boolean indeterminate)
This method sets the progress indicator as determinate or indeterminate.
4 setMax(int max)
This method sets the maximum value of the progress dialog.
5 setProgress(int value)
This method is used to update the progress dialog with some specific value.

6 show(Context context, CharSequence title, CharSequence message)


This is a static method, used to display progress dialog.
4.11 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.
4.11 ListView
-An adapter actually bridges between UI components and
the data source that fill data into UI Component.

- Adapter holds the data and send the data to adapter


view, the view can takes the data from adapter view and
shows the data on different views like as 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.
4.11 ListView Attributes

Sr.No Attribute & Description


1 android:id
This is the ID which uniquely identifies the layout.
2 android:divider
This is drawable or color to draw between list items.

3 android:dividerHeight
This specifies height of the divider. This could be in px, dp, sp, in, or mm.
4 android:entries
Specifies the reference to an array resource that will populate the ListView.

5 android:footerDividersEnabled
When set to false, the ListView will not draw the divider before each footer view.
The default value is true.
6 android:headerDividersEnabled
When set to false, the ListView will not draw the divider after each header view.
The default value is true.
4.11.1 ArrayAdapter

You can use this adapter when your data source is an array.
By default, ArrayAdapter creates a view for each array item
by calling toString() on each item and placing the contents in
a TextView.
Consider you have an array of strings you want to display in a
ListView, initialize a new ArrayAdapter using a constructor
to specify the layout for each string and the string array −

ArrayAdapter adapter = new


ArrayAdapter<String>(this,R.layout.ListView,StringArray);
4.11.1 ArrayAdapter

Here are arguments for this constructor −


First argument this is the application context.
Most of the case, keep it this.
Second argument will be layout defined in XML file and
having TextView for each string in the array.
Final argument is an array of strings which will be populated
in the text view.
Once you have array adapter created, then simply
call setAdapter() on your ListView object as follows −

ListView listView = (ListView) findViewById(R.id.listview);


listView.setAdapter(adapter);
4.12 GridView

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
4.12 GridView

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.
4.12 GridView Attributes

Sr.No Attribute & Description


android:id
1
This is the ID which uniquely identifies the layout.
android:columnWidth
2 This specifies the fixed width for each column. This could be in px,
dp, sp, in, or mm.
android:gravity
3 Specifies the gravity within each cell. Possible values are top,
bottom, left, right, center, center_vertical, center_horizontal etc.
android:horizontalSpacing
4 Defines the default horizontal spacing between columns. This could
be in px, dp, sp, in, or mm.
4.12 GridView Attributes

Sr.No Attribute & Description


android:numColumns
Defines how many columns to show. May be an integer value, such as
5
"100" or auto_fit which means display as many columns as possible to fill
the available space.
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.
6
•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
7 Defines the default vertical spacing between rows. This could be in px, dp,
sp, in, or mm.
4.13 ImageView

- In Android, ImageView class is used to display an


image file in application.

- Image file is easy to use but hard to master in


Android, because of the various screen sizes in
Android devices.

- An android is enriched with some of the best UI


design widgets that allows us to build good looking
and attractive UI based application.
4.13 ImageView Attribute

1. id: id is an attribute used to uniquely identify


a image view in android.
2. src: src is an attribute used to set a source file or
you can say image in your imageview.
3. background: background attribute is used to set
the background of a ImageView.
4. scaleType: scaleType is an attribute used to
control how the image should be re-sized or
moved to match the size of this image view. The
value for scale type attribute can be fit_xy,
center_crop, fitStart etc.
4.13 Imageview Attribute
5. padding: padding attribute is used to set the padding
from left, right, top or bottom of the Imageview.

paddingRight: set the padding from the right side of the


image view.
paddingLeft: set the padding from the left side of the
image view.
paddingTop: set the padding from the top side of the
image view.
paddingBottom: set the padding from the bottom side of
the image view.
padding: set the padding from the all side’s of the image
view.
4.14 ScrollView
- In android, ScrollView is a kind of layout that is
useful to add vertical or horizontal scroll bars to the
content which is larger than the actual size
of layouts such as linearlayout , relativelayout ,
framelayout, etc.

- Generally, the android ScrollView is useful when


we have content that doesn’t fit our android app
layout screen. The ScrollView will enable a scroll to
the content which is exceeding the screen layout and
allow users to see the complete content by scrolling.
4.14 ScrollView

-The android ScrollView can hold only one direct child.


In case, if we want to add multiple views within the scroll
view, then we need to include them in another standard
layout like linearlayout, relativelayout, framelayout, etc.

- To enable scrolling for our android


applications, ScrollView is the best option but we should
not use ScrollView along with ListView
or Gridview because they both will take care of their
own vertical scrolling.
4.14 ScrollView

- In android, ScrollView supports only vertical scrolling.


In case, if we want to implement horizontal scrolling,
then we need to use a HorizontalScrollView component.
4.14.1 ScrollView Attributes

Sr.No Attribute & Description


android:id
1
This is the ID which uniquely identifies the layout.
android:scrollbars
This specifies the alignment of scrollbar.
2
a. Vertical
b. horizontal
4.15 Custom Toast Alert
- In Android, Toast is used to display information for
a period of time.

- It contains a message to be displayed quickly and


disappears after specified period of time. It does not
block the user interaction.

-Toast is a subclass of Object class.


In this we use two constants for setting the duration
for the Toast.

-Toast notification in android always appears near the


bottom of the screen.
4.15 Custom Toast Alert
eg.

Toast msg=Toast.makeText(this,“This is toast msg automtically fade


away:”, Toast.LENGTH_SHORT);

msg.show();
4.16 TimePicker

In Android, TimePicker is a widget used for selecting


the time of the day in either AM/PM mode or 24
hours mode.

The displayed time consist of hours, minutes and


clock format.

If we need to show this view as a Dialog then we


have to use a TimePickerDialog class.
4.16.1 Methods of TimePicker

1. setCurrentHour(Integer currentHour):
This method is used to set the current hours in a time
picker.

2. setCurrentMinute(Integer currentMinute):
This method is used to set the current minutes in a
time picker.

3. getCurrentHour():
This method is used to get the current hours from a
time picker.
4.16.1 Methods of TimePicker

4. getCurrentMinute():
This method is used to get the current minutes from a
time picker.

5. setIs24HourView(Boolean is24HourView):
This method is used to set the mode of the Time
picker either 24 hour mode or AM/PM mode. In this
method we set a Boolean value either true or false.
True value indicate 24 hour mode and false value
indicate AM/PM mode.

6. is24HourView():
4.16.1 Methods of TimePicker

6. is24HourView():
This method is used to check the current mode of the
time picker. This method returns true if its 24 hour
mode or false if AM/PM mode is set.
4.16.1 AttributesTimePicker

Sr.No Attribute & Description


android:id
1
This is the ID which uniquely identifies the layout.
timePickerMode:
2 Time picker mode is an attribute of time picker used to set the
mode either spinner or clock
background:
background attribute is used to set the background of a time
3
picker. We can set a color or a drawable image in the
background.
padding: padding attribute is used to set the padding from left,
4
right, top or bottom for a time picker.
4.16 DatePicker

1. In Android, DatePicker is a widget used to select a


date.

2. It allows to select date by day, month and year in


your custom UI (user interface).

3. If we need to show this view as a dialog then we


have to use a DatePickerDialog class.
4.16.1 Methods of DatePicker

1. setSpinnersShown(boolean shown):
This method is used to set whether the spinner of
the date picker in shown or not. In this method you
have to set a Boolean value either true or false. True
indicates spinner is shown, false value
indicates spinner is not shown.

2. getDayOfMonth():
This method is used to get the selected day of the
month from a date picker. This method returns an
integer value.
4.16.1 Methods of DatePicker

3. getMonth():
This method is used to get the selected month from a
date picker. This method returns an integer value.

4. getYear():
This method is used to get the selected year from a
date picker. This method returns an integer value.

5. getFirstDayOfWeek():
This method is used to get the first day of the week.
This method returns an integer value.
4.16.1 Attributes DatePicker

Sr.No Attribute & Description


android:id
1
This is the ID which uniquely identifies the layout.
datePickerMode: This attribute is used to set the Date Picker
2
in mode either spinner or calendar.
background:
background attribute is used to set the background of a Date
3
picker. We can set a color or a drawable image in the
background.
padding: padding attribute is used to set the padding from left,
4
right, top or bottom for a Date picker.
Socket
Thank You
 Network socket is an endpoint of an inter-
process communication flow across a
computer network.

 Sockets provide the communication


mechanism between two computers using
TCP/IP.
Chapter
Unit V 04

Networking and Security


Activity and Multimedia with Databases

Hours: 18 Marks: 20

Presented by:

Prof. S.S.Bhosale
Pravara Polytechnic, Loni
Specific Objective

Create Android application using


database.
5.1 Intent

Android uses Intent for communicating between


the components of an Application and also from
one application to another application.

Intent are the objects which is used in android


for passing the information among Activities in
an Application and from one app to another also.

Intent are used for communicating between the


Application components and it also provides the
connectivity between two apps.
5.1 Intent
Intent facilitate you to redirect your activity to another
activity on occurrence of any event.
By calling, startActivity() you can perform this task.
eg.
Intent intent = new Intent(getApplicationContext(),
SecondActivity.class);
startActivity(intent);

In the above example, foreground activity is getting


redirected to another activity i.e. SecondActivity.java.
getApplicationContext() returns the context for your
foreground activity.
5.1 Types of Intents:
Intent are of two types:
Explicit Intent and Implicit Intent
5.1 Implicit Intent:
In Implicit Intents we do need to specify the name of the
component.

We just specify the Action which has to be performed


and further this action is handled by the component of
another application.

The basic example of implicit Intent is to open any web


page
5.1 Implicit Intent:
Explicit intent going to be connected internal world of
application, suppose if you wants to connect one
activity to another activity, we can do this quote by
explicit intent, below image is connecting first activity
to second activity by clicking button.
5.1 Implicit Intent:
Let’s take an example to understand Implicit Intents
more clearly.
We have to open a website using intent in your
application.
eg.

Intent intentObj = new Intent(Intent.ACTION_VIEW);


intentObj.setData(Uri.parse("https://www.google.com"));
startActivity(intentObj);
5.1 Explicit Intent:
Explicit Intents are used to connect the application
internally.
In Explicit we use the name of component which will be
affected by Intent.
For Example: If we know class name then we can
navigate the app from One Activity to another activity
using Intent.
In the similar way we can start a service to download a
file in background process.
5.1 Explicit Intent:
Explicit Intent work internally within an application to
perform navigation and data transfer.

eg.

Intent intent = new Intent(getApplicationContext(),


SecondActivity.class);
startActivity(intent);
5.1 intent filter
- An intent filter is an instance of the intent filter class.

- Intent filters are helpful while using implicit intents, It


is not going to handle in java code, we have to set it up
in AndroidManifest.xml.

- Android must know what kind of intent it is launching


so intent filters give the information to android about
intent and actions.

- Before launching intent, android going to do <action>


, <category> and <data> .
5.1 intent filter
Elements In Intent Filter:

There are following three elements in an intent filter:

1. action
2. data
3. category
5.1 intent filter
1. action:

It represent an activities action, what an activity is going


to do. It is declared with the name attribute as given
below
<action android:name = "string" />

An Intent Filter element must contain one or more


action element. Action is a string that specifies the
action to perform.
5.1 intent filter

You can declare your own action as given below.


But we usually use action constants defined by Intent
class.

Intent intentObj = new Intent(Intent.ACTION_VIEW);


intentObj.setData(Uri.parse("https://www.facebook.com"));
startActivity(intentObj);
5.1 intent filter
2. Data:
There are two forms in which you can pass the data,
using URI(Uniform Resource Identifiers) or MIME type
of data.

The syntax of data attribute is as follows:

<data android:scheme="string" android:host="string"


android:port="string" android:path="string"
android:pathPattern="string"
android:pathPrefix="string"
android:mimeType="string" />
5.1 intent filter
3. Category:
This attribute of Intent filter dictates the behavior or
nature of an Intent. There is a string which contains
some additional information about the intent which will
be handled by a component. The syntax of category is
as follows:

<category android:name="string" />


Most of Intents do not require a category for example:

CATEGORY_BROWSABLE,
CATEGORY_LAUNCHER.
5.1 intent filter
BROWSABLE – Browsable category, activity allows itself to
be opened with web browser to open the reference link provided
in data.

LAUNCHER – Launcher category puts an activity on the top of


stack, whenever application will start, the activity containing this
category will be opened first.

<intent-filter> <!--Code here-->


<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter> <!--Code here--> <category
android:name="android.intent.category.BROWSABLE" />
</intent-filter>
5.1 intent filter
ACTION DATA MEANING
Opens phone application and
Intent.ACTION_CALL tel:phone_number
calls phone number
Opens phone application and
Intent.ACTION_DIAL tel:phone_number dials (but doesn’t call)
phone_number
Opens phone application and
Intent.ACTION_DIAL voicemail: dials (but doesn’t call) the voice
mail number.
Opens the maps Application
Intent.ACTION_VIEW geo:lat,long
centered on (lat, long).
Opens the maps application
Intent.ACTION_VIEW geo:0,0?q=address centered on the specified
address.

http://url Opens the browser application


Intent.ACTION_VIEW
https://url to the specified address.

Opens the browser application


Intent.ACTION_WEB_SEARCH plain_text and uses Google search for
given string
5.2 Activity Lifecycle
5.3 Broadcast Receivers
5.3 Broadcast Receivers

Broadcast Receivers simply respond to broadcast


messages from other applications or from the system
itself.

These messages are sometime called events or intents.

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.
5.3 Broadcast Receivers

There are following two important steps to make


BroadcastReceiver works for the system broadcasted
intents –

1. Creating the Broadcast Receiver.


2. Registering Broadcast Receiver
5.3 Broadcast Receivers
1. Creating the Broadcast Receiver

A broadcast receiver is implemented as a subclass


of BroadcastReceiver class and overriding the
onReceive() method where each message is received as
a Intent object parameter.

public class MyReceiver extends BroadcastReceiver {


@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Intent Detected.",
Toast.LENGTH_LONG).show();
}}
5.3 Broadcast Receivers

2. Registering Broadcast Receiver

An application listens for specific broadcast intents by


registering a broadcast receiver
in AndroidManifest.xml file.
Consider we are going to register MyReceiver for
system generated event

ACTION_BOOT_COMPLETED which is fired by the


system once the Android system has completed the boot
process.
5.3 Broadcast Receivers

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<receiver android:name="MyReceiver">
<intent-filter>
<action
android:name="android.intent.action.BOOT_COMPLETED">
</action>
</intent-filter>
</receiver>
</application>
5.3 Broadcast Receivers
Sr.No Event Constant & Description
android.intent.action.BATTERY_CHANGED
1 Sticky broadcast containing the charging state, level, and other information about the battery.
android.intent.action.BATTERY_LOW
2 Indicates low battery condition on the device.

android.intent.action.BATTERY_OKAY
3 Indicates the battery is now okay after being low.

android.intent.action.BOOT_COMPLETED
4 This is broadcast once, after the system has finished booting.

android.intent.action.BUG_REPORT
5
Show activity for reporting a bug.
android.intent.action.CALL
6
Perform a call to someone specified by the data.
android.intent.action.CALL_BUTTON
7 The user pressed the "call" button to go to the dialer or other appropriate UI for placing a call.
android.intent.action.DATE_CHANGED
8
The date has changed.
5.4 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 a database, in files,
or even over a network.
5.4 Content provider

Sometimes it is required to share data across applications.


This is where content providers become very useful.
5.4 Content provider

- Content providers let you centralize content in one place


and have many different applications access it as needed.
- A content provider behaves very much like a database
where you can query it, edit its content, as well as add or
delete content using insert(), update(), delete(), and query()
methods.
- In most cases this data is stored in an SQlite database.

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 My Application extends ContentProvider { }
5.5 Fragment

-A Fragment is a piece of an activity which enable


more modular activity design.
-A fragment is a kind of sub-activity.

Following are important points about fragment :


- A fragment has its own layout and its own behavior
with its own life cycle callbacks.
- You can add or remove fragments in an activity while
the activity is running.
- You can combine multiple fragments in a single
activity to build a multi-pane UI.
5.5 Fragment

- A fragment can be used in multiple activities.


Fragment life cycle is closely related to the life
cycle of its host activity which means when the
activity is paused, all the fragments available in
the activity will also be stopped.
- A fragment can implement a behavior that has
no user interface component.
- Fragments were added to the Android API in
Honeycomb version of Android which API
version 11.
5.5 Fragment
how two UI modules defined by fragments can be combined into
one activity for a tablet design, but separated for a handset
design.
5.4 Fragment Life Cycle
5.4 Types of Fragments

Basically fragments are divided as three stages as shown below.

1. Single frame fragments:


Single frame fragments are using for hand hold devices like
mobiles, here we can show only one fragment as a view.

2. List fragments:
fragments having special list view is called as list fragment

3. Fragments transaction:
Using with fragment transaction. we can move one fragment to
another fragment.
5.5 Services
A service is a component that runs in the background
to perform long-running operations without needing to
interact with the user and it works even if application
is destroyed.
A service can essentially take two states :

1. Started:
A service is started when an application component,
such as an activity, starts it by calling startService().
Once started, a service can run in the background
indefinitely, even if the component that started it is
destroyed.
5.5 Services

2. Bound:

A service is bound when an application component


binds to it by calling bindService().

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).
5.5 Services
5.5.1 Permissions

App permissions help support user privacy by


protecting access to the following:

Restricted data, such as system state and a user's


contact information.
Restricted actions, such as connecting to a paired
device and recording audio.

Android categorizes permissions into different types,


including install-time permissions, runtime
permissions, and special permissions.
5.5.1 Permissions
Each permission's type indicates the scope of restricted data
that your app can access, and the scope of restricted actions that
your app can perform, when the system grants your app that
permission.
To add external storage the permission to read and write. For
that you need to add permission in android Manifest file.
Open AndroidManifest.xml file and add permissions to it just
after the package name.
eg.
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE”>
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE”>

<uses-permission android:name="android.permission.INTERNET“>
5.6 Android MediaPlayer class

- Android provides many ways to control playback of


audio/video files and streams.
- One of this way is through a class called MediaPlayer.
Android is providing MediaPlayer class to access built-in
mediaplayer services like playing audio,video e.t.c.
- In order to use MediaPlayer, we have to call a static
Method create() of this class.
- This method returns an instance of MediaPlayer class.
Its syntax is as follows :

MediaPlayer mediaPlayer = MediaPlayer.create(this, R.raw.song);


5.6 Android MediaPlayer class

- The second parameter is the name of the song that you


want to play.
- You have to make a new folder under your project with
name raw and place the music file into it.
-Once you have created the Mediaplayer object you can
call some methods to start or stop the music.

These methods are listed below:

mediaPlayer.start();
mediaPlayer.pause();
mediaPlayer.reset();
5.6 Android MediaPlayer class

- On call to start() method, the music will start playing


from the beginning.
- If this method is called again after the pause() method,
the music would start playing from where it is left and not
from the beginning.
- In order to start music from the beginning, you have to
call reset() method.

Its syntax is given below:

mediaPlayer.reset();
5.6 Android MediaPlayer class

Sr.No Method & description


1 isPlaying()
This method just returns true/false indicating the song is
playing or not
2 seekTo(position)
This method takes an integer, and move song to that particular
position millisecond
3 getCurrentPosition()
This method returns the current position of song in milliseconds
4 getDuration()
This method returns the total time duration of song in
milliseconds
5 reset()
This method resets the media player
5.6 Android MediaPlayer class

Sr.No Method & description


6 release()
This method releases any resource attached with
MediaPlayer object
7 setVolume(float leftVolume, float rightVolume)
This method sets the up down volume for this player
8 setDataSource(FileDescriptor fd)
This method sets the data source of audio/video file
9 selectTrack(int index)
This method takes an integer, and select the track from the
list on that particular index
10 getTrackInfo()
This method returns an array of track information
5.7 Video Player

-In Android, VideoView is used to display a video file.


- It can load images from various sources (such as content
providers or resources) taking care of computing its
measurement from the video
-You have to create a new raw folder in res directory.

VideoView code In XML Android:

<VideoView android:id="@+id/vdv1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
5.7 Video Player

VideoView v1=(VideoView)findViewById(R.id.vdv1);

// set Media Controller to enable play,pause,forword etc

MediaController media=new MediaController(this);


media.setAnchorView(v1);

//Location of media file


Uri uri=
Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.video2);
v1.setMediaController(media);
v1.setVideoURI(uri);
v1.requestFocus();
v1.start();
5.8 TexttoSpeech

- Android allows you convert your text into voice.


- Not only you can convert it but it also allows you to speak text in
variety of different languages.
- Android provides TextToSpeech class for this purpose.
- In order to use this class, you need to instantiate an object of this
class and also specify the initListener.

Its syntax is given below :

private EditText write;


ttobj=new TextToSpeech(getApplicationContext(), new
TextToSpeech.OnInitListener()
{ @Override
public void onInit(int status)
{ } });
5.8 TexttoSpeech

- Different Language can be set by calling setLanguage() method.


Its syntax is given below :

ttobj.setLanguage(Locale.UK);
- The method setLanguage takes an Locale object as parameter.
- The list of some of the locales available are given below :
Sr.No Locale
1 US
2 CANADA_FRENCH
3 GERMANY
4 ITALY
5 JAPAN
6 CHINA
5.9 Sensors
-Most of the android devices have built-in sensors that measure
motion, orientation, and various environmental condition.
-The android platform supports three broad categories of
sensors.

1. Motion Sensors
2. Environmental sensors
3. Position sensors

- Some of the sensors are hardware based and some are


software based sensors.
- Whatever the sensor is, android allows us to get the raw data
from these sensors and use it in our application.
5.9 Sensors

- For this android provides us with some classes.


- Android provides SensorManager and Sensor classes to
use the sensors in our application.
- In order to use sensors, first thing you need to do is to
instantiate the object of SensorManager class.
It can be achieved as follows:

SensorManager sMgr; sMgr =


(SensorManager)this.getSystemService(SENSOR_SERVICE);
5.10 Camera

You will use MediaStore.ACTION_IMAGE_CAPTURE to


launch an existing camera application installed on your
phone.
Its syntax is given below

Intent intent = new


Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
5.10 Camera
Sr.No Intent type and description
ACTION_IMAGE_CAPTURE_SECURE
1 It returns the image captured from the camera , when the device is
secured
ACTION_VIDEO_CAPTURE
2 It calls the existing video application in android to capture video
EXTRA_SCREEN_ORIENTATION
3
It is used to set the orientation of the screen to vertical or landscape
EXTRA_FULL_SCREEN
4
It is used to control the user interface of the ViewImage
INTENT_ACTION_VIDEO_CAMERA
5 This intent is used to launch the camera in the video mode
EXTRA_SIZE_LIMIT
6
It is used to specify the size limit of video or image capture size
5.11 Bluetooth

- Among many ways, Bluetooth is a way to send or receive


data between two different devices.
- Android platform includes support for the Bluetooth
framework that allows a device to wirelessly exchange data
with other Bluetooth devices.
- Android provides Bluetooth API to perform these
different operations.

-Scan for other Bluetooth devices


-Get a list of paired devices
-Connect to other devices through service discovery
5.11 Bluetooth

-Android provides BluetoothAdapter class to communicate


with Bluetooth.
- Create an object of this calling by calling the static
method getDefaultAdapter().

Its syntax is given below:

private BluetoothAdapter BA;


BA = BluetoothAdapter.getDefaultAdapter();
5.11 Bluetooth

In order to enable the Bluetooth of your device:

Intent turnOn = new


Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(turnOn, 0);

Once you enable the Bluetooth , you can get a list of paired
devices by calling getBondedDevices() method.
It returns a set of bluetooth devices.
Its syntax is:

private Set<BluetoothDevice>pairedDevices; pairedDevices =


BA.getBondedDevices();
5.11 Bluetooth
Sr.No Method & description
enable()
1
This method enables the adapter if not enabled
isEnabled()
2
This method returns true if adapter is enabled
disable()
3
This method disables the adapter
getName()
4
This method returns the name of the Bluetooth adapter
setName(String name)
5
This method changes the Bluetooth name
getState()
6
This method returns the current state of the Bluetooth Adapter.
startDiscovery()
7 This method starts the discovery process of the Bluetooth for 120 seconds.
5.12 Animation

- Animation is the process of creating motion and shape


change

Tween Animation:
- Tween Animation takes some parameters such as start
value , end value, size , time duration , rotation angle etc.
and perform the required animation on that object.
- It can be applied to any type of object.
So in order to use this , android has provided us a class
called Animation.
5.12 Animation

- In order to perform animation in android , we are going to


call a static function loadAnimation() of the class
AnimationUtils.
- We are going to receive the result in an instance of
Animation Object.
Its syntax is as follows :

Animation animation =
AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.myanimation);
5.12 Animation

- This animation class has many useful functions which are


listed below :
- In order to apply this animation to an object , we will just
call the startAnimation() method of the object.
Its syntax is :

ImageView image1 = (ImageView)findViewById(R.id.imageView1);


image1.startAnimation(animation);
5.12 Animation

Sr.No Method & Description


start()
1
This method starts the animation.
setDuration(long duration)
2 This method sets the duration of an animation.

getDuration()
3 This method gets the duration which is set by above method

end()
4
This method ends the animation.
cancel()
5 This method cancels the animation.
5.13 SQLite Database

SQLite is a Structure query base database, open source,


light weight, no network access and standalone database.
It support embedded relational database features.
5.13 SQLite Database

SQLite is an open-source relational database i.e. used to


perform database operations on android devices such as
storing, manipulating or retrieving persistent data from the
database.

It is embedded in android by default. So, there is no need to


perform any database setup or administration task.

SQLiteOpenHelper class provides the functionality to use


the SQLite database.
5.13 SQLite Database

- SQLite 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
etc.
Database – Package

The main package is android.database.sqlite that contains


the classes to manage your own databases
5.13 SQLite Database

Database - Creation
In order 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 mydatabase = openOrCreateDatabase("your


database name",MODE_PRIVATE,null);
5.13 SQLite Database
Sr.No Method & Description
1 openDatabase(String path, SQLiteDatabase.CursorFactory factory, int
flags, DatabaseErrorHandler errorHandler)
This method only opens the existing database with the appropriate flag mode.
The common flags mode could be OPEN_READWRITE OPEN_READONLY
2 openDatabase(String path, SQLiteDatabase.CursorFactory factory, int
flags)
It is similar to the above method as it also opens the existing database but it
does not define any handler to handle the errors of databases
3 openOrCreateDatabase(String path, SQLiteDatabase.CursorFactory
factory)
It not only opens but create the database if it not exists. This method is
equivalent to openDatabase method.
4 openOrCreateDatabase(File file, SQLiteDatabase.CursorFactory factory)
This method is similar to above method but it takes the File object as a path
rather then a string. It is equivalent to file.getPath()
5.13 SQLite Database

Database - Insertion
we can create table or insert data into table using execSQL
method defined in SQLiteDatabase class.

Its syntax is given below:

mydatabase.execSQL("CREATE TABLE IF NOT EXISTS


poly(Username VARCHAR,Password VARCHAR);");
mydatabase.execSQL("INSERT INTO poly
VALUES('admin','admin');");
5.13 SQLite Database

Sr.No Method & Description


1 execSQL(String sql, Object[] bindArgs)
This method not only insert data , but also used to update or modify
already existing data in database using bind arguments
5.13 SQLite Database
Sr.No Method & Description
1 getColumnCount()
This method return the total number of columns of the table.
2 getColumnIndex(String columnName)
This method returns the index number of a column by specifying the name of the column

3 getColumnName(int columnIndex)
This method returns the name of the column by specifying the index of the column

4 getColumnNames()
This method returns the array of all the column names of the table.

5 getCount()
This method returns the total number of rows in the cursor
6 getPosition()
This method returns the current position of the cursor in the table
7 isClosed()
This method returns true if the cursor is closed and return false otherwise
5.13.1 Database Helper class

Database - Helper class

For managing all the operations related to the database , an


helper class has been given and is called.
eg.

SQLiteOpenHelper openHelper=new
databaseHelper(this);

To Write data into database:

SQLiteDatabase db=openHelper.getWritableDatabase();
5.13.1 Database Helper class
Its syntax is given below:
public class databaseHelper extends SQLiteOpenHelper
{
public databaseHelper(@Nullable Context context) {
}
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " +TABLE_NAME+ "(ID INTEGER
PRIMARY KEY AUTOINCREMENT,name TEXT,address
TEXT,phone TEXT,email TEXT)");
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME);
onCreate(db);
}
}
Socket
Thank You
❑ Network socket is an endpoint of an inter-
process communication flow across a
computer network.

❑ Sockets provide the communication


mechanism between two computers using
TCP/IP.

You might also like