Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Team Emertxe
Android
Deep dive into developing MobileApp using Android
Android Fundamentals
What is Android
What is Android?
● Android is an OS primarily designed for mobile devices
● Built on Linux Kernel
● Java, the main program...
History And Versions
Version Release
Date
Features
1.6
(Donut)
15 Sep 2009•Improved Android Market experience
•Gallery now enables users to sel...
Version Release
Date
Features
2.0/2.1
(Eclair)
26 Oct
2009
• New capabilities in Accounts, contacts & Sync
Management
• Qu...
Version Release Date Features
2.2
(Froyo)
20 May 2010 • OS speed, memory, and performance optimizations
•Dalivk JIT Compli...
Version Release
Date
Features
2.3
(Gingerbread
)
6 Dec
2010
• Updated user interface design
• New audio effects
• Support ...
Version Release
Date
Features
3.1 and 3.3
(Honeycomb)
22 Feb
2011
• It was the first Android OS version which was
specific...
Version Release
Date
Features
4.0(Ice Cream
Sandwich)
19 Oct
2011
● New typeface called Roboto
● New Face unlock feature
●...
Version Release
Date
Features
4.1, 4.2 and
4.3(Jelly Bean)
27 June
2012
● User interface has been made faster and smoother...
Version Release Date Features
4.4 (KitKat) November
2013
● Faster Multi-tasking
● A smarter caller id
● Print where ever, ...
Version Release Date Features
5.0 (Lollipop) November
2014
● Support for 64-bit CPUs
● Support for print previews
● Audio ...
Version Release Date Features
6.0
(Marshmallow)
17 August
2015
• Android Pay
• Fingerprint Scan Standardization
• App Perm...
Android Version And
Features
Version Release Date Features
Android
N
Installing Software
Installing Android Software
● Download jdk 8 from below link
http://www.oracle.com/technetwork/java/javase/downloads/
jdk8...
Installing Android Software
Setting JAVA_HOME and ANDROID_HOME environment variable
● Right click windows icon and select ...
Installing Android Software
Select Advance system settings
Installing Android Software
Select Environment Variables
Installing Android Software
Define JAVA_HOME and ANDROID_HOME Environment Variables
Android Studio Welcome
Screen
Hello Android Example
Hello Android Example
Summary steps to develop an Android application :
● Install Android Studio
● Create an Android Virtu...
Hello Android Example
Tools used in this tutorial :
● JDK 8
● Android Studio 2.1
What is Android Studio?
● Android Studio is the official Integrated
Development Environment (IDE) for Android app
developm...
What is Android Studio?
● Code templates and GitHub integration to help you
build common app features and import sample
co...
Android Studio –
Project Structure
● A project in Android Studio contains
following, one or more, modules with
source code...
Android Studio –
Project Structure
● By default, Android Studio displays
project files in the Android project
view
● All t...
Android Studio –
User interface
● Toolbar  - Running your app and launching
Android tools
● Navigation bar - Navigate thro...
Android Studio –
Gradle Build
● Android Studio build files are named build.gradle
● They are plain text files that use Gro...
Android Studio –
Tools
● SDK Tools
– Virtual Device tools
– Development tools
– Debugging tools
– Build Tools
– Image Tool...
Android Studio –
Virtual Device Tools
● Android Virtual Device Manager
– The AVD Manager provides a graphical user interfa...
Android Studio –
Development Tools
● Hierarchy Viewer (hierarchyviewer)
– Visual representation of the layout's View hiera...
Android Studio –
Debug and Profile Tools
● Android Monitor
– Is integrated into Android Studio and provides logcat,
memory...
Android Studio –
Debug and Profile Tools
● Device Monitor
– A stand-alone tool that provides a graphical user
interface fo...
Android Studio –
Platform Tools
● Android Debug Bridge (adb)
– A versatile tool that lets you manage the state of an
emula...
Android Architecture/Software Stack
Android Architecture
40
Architecture Detail
● Android is built on Linux 3.x kernel
● Does not include the full set of standard Linux utilities
● I...
Architecture Detail
● It has a core capability like:
– Display Driver
– Camera Driver
– Bluetooth Driver
– Flash Memory Dr...
Libraries
● Native libraries.
● Written in C/C++ internally
● Called through Java wrapper APIs
● Layer contains
– Surface ...
Functional Libraries -
WebKit
● Open source WebKit browser: http://webkit.org
● Renders pages in full (desktop) view
● Ful...
SQLite
● Server less, transactional SQL database engine.
● Most widely deployed SQL database engine in the world.
● Light-...
Dalvik Virtual Machine
Dalvik Virtual Machine
● Highly optimized VM, compiled byte is optimized for mobile
devices
● Register based NOT Stack bas...
Application Framework
● Content Providers – access, store and share application data
● Resource Manager - access to string...
Application Layer
● Collection of built-in and 3rd party apps
● Built-in apps - Phone and Web Browser
● Google and 3rd par...
Dalvik Runtime
● Dalvik is the virtual machine (VM) in Android OS
● Used on mobile devices such as mobile phones, tablets ...
Dalvik Runtime
● Multiple classes are included in a single .dex file.
● As of Android 2.2, Dalvik has a just-in-time compi...
Dalvik vs JVM
Dalvik Virtual machine (DVM)
● Register Architecture
● Designed to run on low memory,
● Uses its own byte co...
Android Runtime
● Android application == a process
● A process == an instance of the Dalvik virtual machine.
● Dalvik can ...
Android App Building Blocks
Objectives
At the end of this module you will be able
to:
● Recognize Essential app components
– Activity
– Services
– Bro...
App Building Blocks
Component
s
Messages Resources Configurati
on
Activity Intent Icons App Manifest
Services Notification...
App Building Blocks -
Activity
Activities in
an App
“An Activity is an application component that provides a
screen with w...
App Building Blocks -
Activity
● Activity - UI component
● Activities are stacked like a deck of
cards
● Only one is visib...
● Each activity is given a window in which to draw its
user interface
● An application usually consists of multiple activi...
● Each time a new activity starts, the previous activity is
stopped, but the system preserves the activity in a stack
(the...
● There are several callback methods that an activity
might receive, due to a change in its state - whether
the system is ...
Android Building Blocks -
Activity (Life Cycle)
Method Usage
onCreate() Called when activity is created first time;
activi...
App Building Blocks -
Services
“A Service is an application component that can
perform long-running operations in the back...
● Faceless task that runs in the background
● No visual user interface
● Can run indefinitely unless stopped
● Each servic...
● Broadcast receivers are dormant listeners that can
register for various system or application events (intents)
● Static ...
● Broadcast can be Initiated by System and Apps
● Battery low, External power
connected/disconnected, Screen on/off are
ex...
● Normal broadcasts (sent with Context.sendBroadcast)
– Completely asynchronous
– All receivers of the broadcast are run i...
App Building Blocks -
Content Provider
● Content providers manage access to a structured set of
data
● They encapsulate th...
App Building Blocks -
Content Provider
Content Provider Content Resolver
Remote
DB
File
Local DB
Application Application
A...
● Extends the ContentProvider base class
● An application accesses the data from a content
provider with a ContentResolver...
App Building Blocks -
Intent
“An intent is an abstract description of an operation to
be performed”
“An Intent is a messag...
App Building Blocks -
Intent
● Intent is used to
– Launch an Activity
– Switch between Activities
– Broadcast intent to Bo...
App Building Blocks -
Intent
● Provides late runtime binding
– Set and respond to notifications or status changes
– Can wa...
App Building Blocks -
Notifications
● A notification is a message displayed to
the user outside of application's normal
UI...
App Building Blocks -
Notifications
● Object of Notification class
● Notify the user about events
● Sent through Notificat...
App Building Blocks -
Resources
● Always externalize resources such as images and strings
from your application code, so t...
App Building Blocks -
Resources
● Default resources are those that should be used regardless
of the device configuration o...
App Building Blocks -
App Manifest
● Every application must have an AndroidManifest.xml file
(with precisely that name) in...
App Building Blocks -
App Manifest
● It describes the components of the application
● It determines which processes will h...
App Building Blocks -
View and ViewGroup
● All user interface elements in an Android app are built using
View and ViewGrou...
App Building Blocks -
View and ViewGroup
● View Group is an invisible container that organizes child views
● Child Views m...
App Building Blocks -
View and ViewGroup
● Android compiles the XML layout code that is later loaded in
code usually by
pu...
App Building Blocks -
View and ViewGroup
● View and ViewGroup trees build up complex GUIs
●
Android framework is responsib...
Android Tools
Objectives
At the end of this module you will be able to:
● Understand about Emulator
● Eclipse plugin
● Debugging
● DDMS
Emulator
● Emulator runs same system image as a device.
Debugging
DDMS
AndroidManifest.xml
● Starts with tag <manifest>
● uses-sdk
● uses-configuration
● uses-feature
● supports-screens
● Appli...
ADB
Questions
● What is Android?
● What are Android Features?
● What is the difference between Dalvik and JVM?
User Interface
Agenda
● Why is UI important?
● Bad UI
● Good UI
● Application UI design philosophy
● Android UI features
● Basic android ...
Why is UI important?
• Better UI
• Perceived quality + polish
• Better rating
• Better app ranking
• More installs/purchas...
Bad UI
Too many views
Bad UI
Too many colors?
Good UI
Clear design
Application UI Design
Philosophy
• “Successful application will offer an outstanding
end-user experience”
• Fast
• Simple
...
Android UI Features
• Rich UI model, huge number of components
• Code in Java or XML
• Based on the MVC model
• New APIs, ...
Basic Android UI
Elements
• Views
• Layouts
• Shapes
• Colors
• Gradients
Basic UI components
● Button,
● ImageButton,
● CheckBox
● EditText,
● ImageView
● TextView
● ListMenuItemView
● RadioButto...
Basic UI Component
●
Progress Bar
Zoom Slider
●
Zoom Slider
ListView
●
ListView
ScrollView
●
ScrollView
Toast
Toast.makeText(getApplicationC
ontext(),"Button is clicked",
Toast.LENGTH_LONG).show();
Toggle Button
<ToggleButton
android:id="@+id/togglebutton"
android:layout_width="wrap_content"
android:layout_height="wrap...
Switch Button
<Switch
android:id="@+id/mySwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
...
Alert Dialog
Spinner
<Spinner
android:id="@+id/
spinner2"
android:layout_wid
th="match_parent"
android:layout_hei
ght="wrap_conten
t" />
Auto Complete TextView
<AutoCompleteTextView
android:id="@+id/autoCompleteText
View1"
android:layout_width="wrap_content"
...
Rating Bar
<RatingBar
android:id="@+id/ratingBar
"
android:layout_width="wrap
_content"
android:layout_height="wra
p_conte...
Date Picker
<DatePicker
android:id="@+id/dpResult"
android:layout_width="wrap
_content"
android:layout_height="wra
p_conte...
Time Picker
<TimePicker
android:id="@+id/timePicke
r1"
android:layout_width="wrap
_content"
android:layout_height="wra
p_c...
Quick Contact Budge
QuickContactBadge
badgeSmall =
(QuickContactBadge)
findViewById(R.id.badge_sm
all);
badgeSmall.assignC...
Analog Clock and
Digital Clock
●
AnalogClock ac =
(AnalogClock)
findViewById(R.id.analogClo
ck1);
●
DigitalClock dc =
(Dig...
Two UI Approaches
You can mix and match both styles.
Declarative is preferred: easier and more tools
Code XML
You write Ja...
Draw Tool
1
1
8
Activity, Intent & Fragment
What is Activity
● An activity is a single, focused thing that the user can do.
● Almost all activities interact with the ...
Life Cycle of Activity
Android Activity Life
Cycle Example
Intent
● Implicit Intent
●
Explicit Intent
Intent
Intent
Intent
● Implicit Intent
● Explicit Intent
Intent Methods
● Intent intent=new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.google.com"));
startAc...
Fragments
● A Fragment represents a behavior or a portion of user
interface in an Activity.
● You can combine multiple fra...
Fragments
Fragments
Fragment Life Cycle
Fragment Example
Dynamic Fragments
Android Menu
Option Menu
Context Menu
Pop Up Menu
Layout Manager
Layouts
● Layout Managers are extensions of the ViewGroup class
● Control the position of child controls on a screen.
● Ve...
Activities
Android Activity
• Basic unit of an Android application is an Activity.
• May contain widgets like buttons, labels, text b...
Android Activity Flow
●
Load the XML UI in the onCreate() using the
setContentView()
●
Each element in the XML file is com...
Attributes
Attribute Description
layout_widthSpecifies the width of the View or ViewGroup
layout_heightSpecifies the heigh...
Linear Layouts
●
The LinearLayout arranges views in a single column or
single row.
●
Child views can either be arranged ve...
Linear Layout
Linear Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/andro...
Relative Layout
Relative Layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/a...
Table Layout
<?xml version="1.0"
encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas
.android.com/apk/res/androi...
Grid View Layout
<GridView
xmlns:android="http://schemas.android.
com/apk/res/android"
android:id="@+id/gridview"
android:...
Adapter
Adaptor
●
Array Adaptor
●
ArrayList Adaptor
●
Base Adaptor
Array Adaptor
ArrayAdapter<String>
adapter = new
ArrayAdapter<String>(this,
R.layout.rowlayout,
R.id.label, values);
setLi...
View
Grid View
Web View
Scroll View
Search View
Tab Host
Dynamic List View
Expanded List View
View
Grid View
Web View
Scroll View
Search View
Tab Host
Dynamic ListView
Expandable ListView
Services
Objectives
●
What is a Service?
●
Service lifecycles
●
Permissions
●
Local services
●
Remote services
164
When a Service Used?
●
Applications will need to run processes for a long time
without any intervention from the user, or ...
● Services gets higher priority than inactive Activities,
so they’re less likely get to be killed.
● Services run without ...
Two Types of Services
●
Local service
●
Not accessible from other applications
●
Runs in the same process of the applicati...
Service and
Notification
●
Service is a long lived component and does not
implement any user interface of its own.
●
Typic...
Creating a Service
●
To define a Service, create a new class that extends
Service. You’ll need to override onBind and onCr...
Controlling Services
●
Override onStartCommand().
●
Is called whenever the Service is started with a call to
startService,...
What Facilities
Service Provide?
●
A facility for the application to tell the system about something
it wants to be doing ...
Binding to a Service
●
Once a service has begun and is running in the
background, activities can “bind” to the service.
●
...
What Facilities
Service Provide?
●A facility for the application to tell the system about
something it wants to be doing i...
What Facilities
Service Provide?
● A facility for an application to expose some of its
functionality to other applications...
Starting a Service
● If someone calls Context.startService() then the system will
retrieve the service (creating it and ca...
Modes of Operations
For started services, there are two additional major modes of
operation they can decide to run in, dep...
Getting a Connection
to a Service
●
Clients can also use Context.bindService() to obtain a
persistent connection to a serv...
178
Permissions
● Global access to a service can be enforced when it is
declared in its manifest's <service> tag.
● By doi...
Local Service
●
One of the most common uses of a Service is as a secondary
component running alongside other parts of an a...
Remote Messenger
Service
● If you need to be able to write a Service that can perform
complicated communication with clien...
Preferences
● The SharedPreferences class provides a
general framework that allows you to save
and retrieve persistent key-value pairs...
● To get a SharedPreferences object for your application, use
one of two methods:
● getSharedPreferences() - Use this if y...
● To write values:
● Call edit() to get a SharedPreferences.Editor.
Add values with methods such as putBoolean() and
putSt...
● getFilesDir()
● Gets the absolute path to the filesystem directory where
your internal files are saved.
● getDir()
● Cre...
Data Storage
● Android Database
● SQLite Database
● Content Providers
● Cursors and Content Values
● SQLiteOpenHelper
● Querying a Data...
Structured data persistence in Android :
● SQLite Databases : Offers the SQLite relational database
library
● Content Prov...
● Independent relational databases for applications.
● Store and manage complex, structured application data.
● DB stored ...
● All databases are private. Standard database best
practices apply in Android.
● Normalize your data to reduce redundancy...
● SQLite has a reputation for being extremely reliable
and is the database system of choice for many :
● Consumer electron...
● SQLite is a well regarded relational database management
system (RDBMS). It is:
Open-source
Standards-compliant
Lightwei...
● SQLite has a reputation for being extremely reliable
and is the database system of choice for many :
● Consumer electron...
●ContentValues used to insert new rows into tables.
●Queries in Android returned as Cursor objects.
●The startManagingCurs...
Navigation functions including:
● moveToFirst Moves the cursor to the first row in the
query result
● moveToNext Moves the...
● SQLiteOpenHelper is an abstract class :
● Used for creating,
● Opening, and upgrading databases.
● onCreate, and onUpgra...
197
SQLiteOpenHelper
dbHelper = new myDbHelper(context, DATABASE_NAME,
null, DATABASE_VERSION);
SQLiteDatabase db;
try
{
d...
Opening and creating databases without
SQLiteHelper:
●
Create and open databases by using the
openOrCreateData base method...
private static final String DATABASE_NAME = "myDatabase.db";
private static final String DATABASE_TABLE = "mainTable";
pri...
● Database query returns a Cursor.
● To execute needs :
– Optional Boolean – if result set should contain only unique valu...
// Return all rows for columns one and three, no duplicates
String[] result_columns = new String[] {KEY_ID, KEY_COL1,
KEY_...
● First use the moveTo<location> methods described earlier to
position the cursor at the correct row of the result Cursor....
int GOLD_HOARDED_COLUMN = 2;
Cursor myGold = myDatabase.query("GoldHoards", null, null, null, null, null,
null);
float tot...
// Create a new row of values to insert.
ContentValues newValues = new ContentValues();
// Assign values for each row.
new...
// Define the updated row content.
ContentValues updatedValues = new
ContentValues();
// Assign values for each row.
newVa...
myDatabase.delete(DATABASE_TABLE, KEY_ID +
"=" + rowId, null);
206
Deleting Rows
Content Providers
● Content providers store and retrieve data and make it accessible
to all applications.They're the only way to share data ...
● Create, retrieve, update, delete data of a particular type
● Exposes URI for each data set
● Content resolver
● given UR...
210
Content Provider
Content Provider URI
● A Content Provider exposes a unique URI used to query, add, update
and delete data:
– Standard pref...
● Use the existing content provider as is.
● Modify the existing content provider [based on the requirement].
● Write a co...
● To create a new Content Provider, extend the abstract
ContentProvider class.
● Override the onCreate method to create (a...
import android.content.*;
import android.database.Cursor;
import android.net.Uri;
import android.database.SQLException;
pu...
● You should expose a public static CONTENT_URI property that
returns the full URI of this provider.
● A Content Provider ...
● Content URIs can represent either of two forms:
- URI represents a request for all values
- A trailing /<rownumber>, rep...
● Once you have completed your Content Provider, it must be added to
the application manifest.
● Use the authorities tag t...
● Content Resolver includes a number of methods to modify and query
Content Providers.
● Each method accepts a URI that sp...
ContentResolver cr = getContentResolver();
// Return all rows
Cursor allRows = cr.query(MyProvider.CONTENT_URI, null, null...
● Content Provider queries take a form very similar to that of database
queries.
● Query results are returned as Cursors o...
● Media Store is a managed repository of audio, video, and image files.
● Whenever you add a new multimedia file to the fi...
● The Media Store segregates media kept on the
internal and external volumes of the host device.
● Each of the Media Store...
Android Multimedia
Android
Multimedia
Live Wallpaper
Audio And Video
Playing Audio In Android
Playing Video in Android
Android Alarm Manager
Android Gallery
Android Speech API
Android Speech API
● Text to Speech
● Speech to Text
Android Telephony API
Android Telephony Manager
Telephony Manager Example
● Example of TelephonyManager that prints information of the
telephony services.
● Determining w...
Location and Maps
Android Location API
Google Maps
Android Device Connectivity
Agenda
●
How to connect to the Wifi service
●
Scanning all available wifi networks
●
Bluetooth Services
●
How to connect t...
Wifi Service
Connecting to the
Wifi Service
●
To define a Service, create a new class that extends
Service. You’ll need to override onB...
Sample Code to
Scan Wifi Networks
WifiManager wifi;
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo ...
Register a
Broadcast Receiver
if (receiver == null)
receiver = new WiFiScanReceiver(this);
registerReceiver(receiver,
new ...
In the Broadcast
Receiver
In the onReceive method():
List<ScanResult> results = wifiDemo.wifi.getScanResults();
//wifiDemo...
Permissions
●
Global access to a service can be enforced when it is declared in
its manifest's <service> tag.
●
By doing s...
Questions
●
Create a program that will scan all available wifi networks and
display it on the screen
●
When you click a sc...
Bluetooth
Bluetooth Adapter
●
Represents the local Bluetooth adapter (Bluetooth radio).
●
The BluetoothAdapter is the entry-point fo...
Bluetooth Socket
●
Represents the interface for a Bluetooth socket (similar to a
TCP Socket).
●
This is the connection poi...
Bluetooth
Server Socket
● Represents an open server socket that listens for incoming
requests (similar to a TCP ServerSock...
Bluetooth Class
●
Describes the general characteristics and capabilities of a
Bluetooth device.
●
This is a read-only set ...
Connecting to the
Bluetooth Adapter
253
● Here you must get a BluetoothAdapter and then enable
bluetooth.
1. Get Bluetooth...
Android Camera
Android Camera
Android provides the facility to work on camera by 2 ways:
● By Camera Intent
● By Camera API
Android Sensors
Android Sensor
Types of Sensors:
● Motion Sensor
● Position Sensor
● Environmental Sensor
Stay connected
About us: Emertxe is India’s one of the top IT finishing schools &
self learning kits provider. Our primary...
Thank You
Upcoming SlideShare
Loading in …5
×

Android : Deep dive into developing MobileApp using Android

1,987 views

Published on

● Android is a mobile operating system (OS) based on the Linux kernel
and currently developed by Google.
● Android is designed primarily for touchscreen mobile devices such as
smartphones and tablet computers.
● Android's source code is released by Google under open source
licenses.
● Android is the most popular mobile OS. As of 2013, Android devices
sell more than Windows, iOS, and Mac OS devices combined.

Published in: Technology
  • Be the first to comment

Android : Deep dive into developing MobileApp using Android

  1. 1. Team Emertxe Android Deep dive into developing MobileApp using Android
  2. 2. Android Fundamentals
  3. 3. What is Android
  4. 4. What is Android? ● Android is an OS primarily designed for mobile devices ● Built on Linux Kernel ● Java, the main programming language ● Android is Open and Free ● Most of the code available under Apache License ● Developed and distributed by Google ● Managed by Open Handset Alliance (OHA) “Android provides a rich application framework that allows you to build innovative apps and games for mobile devices in Java language environment” “Android provides a rich application framework that allows you to build innovative apps and games for mobile devices in Java language environment”
  5. 5. History And Versions
  6. 6. Version Release Date Features 1.6 (Donut) 15 Sep 2009•Improved Android Market experience •Gallery now enables users to select multiple photos for deletion • Support for CDMA and GSM • Support for more screen sizes and resolutions • Quick search box with updated Voice Search, integration with native applications •Updated technology support text-to-speech engine 6 Android Version And Features
  7. 7. Version Release Date Features 2.0/2.1 (Eclair) 26 Oct 2009 • New capabilities in Accounts, contacts & Sync Management • Quick Contact • Optimized hardware speed • New Browser UI and HTML 5 support • Improved Google Maps 3.1.2 • MicrosoftExchage support • Built in flash support for Camera • MotionEvent class enhanced to track multi-touch events • Improved virtual keyboard • Bluetooth 2.1 • Live Wallpapers/Folder 7 Android Version And Features
  8. 8. Version Release Date Features 2.2 (Froyo) 20 May 2010 • OS speed, memory, and performance optimizations •Dalivk JIT Complier • Improved application launcher with shortcuts to Phone and Browser applications • USB tethering and Wi-Fi hotspot functionality • Automatic App update • Quick switching between multiple keyboard languages and their dictionaries • Support for numeric and alphanumeric passwords • Support for file upload fields in the Browser application • Adobe Flash10.1 support 8 Android Version And Features
  9. 9. Version Release Date Features 2.3 (Gingerbread ) 6 Dec 2010 • Updated user interface design • New audio effects • Support for Near Field Communication • Redesigned multi-touch software keyboard • Enhanced support for native code development • Audio, graphical, and input enhancements for game developers • Concurrent garbage collection for increased performance • Native support for more sensors (such as gyroscopes and barometers) • A download manager for long running downloads • Improved power management and application control 9 Android Version And Features
  10. 10. Version Release Date Features 3.1 and 3.3 (Honeycomb) 22 Feb 2011 • It was the first Android OS version which was specifically designed for tablets. • It adds toolbars at top and bottom and incorporates tabbed browsing and other desktop features. • Honeycomb uses Microsoft's Media Transfer Protocol (see MTP) for file transfer rather than connecting as a USB mass storage device. Android Version And Features
  11. 11. Version Release Date Features 4.0(Ice Cream Sandwich) 19 Oct 2011 ● New typeface called Roboto ● New Face unlock feature ● Android Beam – A secure NFC powered content sharing platform ● Re-arrangeable folders, Favorites Tray, Screenshots ● Swipe to dismiss notifications, tasks and browser tabs ● W-Fi Direct ● Manage apps running in background ● Revamped Gmail interface. Android Version And Features
  12. 12. Version Release Date Features 4.1, 4.2 and 4.3(Jelly Bean) 27 June 2012 ● User interface has been made faster and smoother under Project Butter. ● Notification center has been improved with expandable and actionable notifications ● Off line voice recognition and typing facility. ● Better Google Voice Search. ● Support for external Braille input in enhanced Accessibility options. ● Android Beam with enhanced option to transfer photos and videos. ● Google Now ● App encryption and Smart App updates Android Version And Features
  13. 13. Version Release Date Features 4.4 (KitKat) November 2013 ● Faster Multi-tasking ● A smarter caller id ● Print where ever, when ever. ● Pick a file, any file Android Version And Features
  14. 14. Version Release Date Features 5.0 (Lollipop) November 2014 ● Support for 64-bit CPUs ● Support for print previews ● Audio input and output through USB devices ● Android Runtime (ART) with ahead-of-time (AOT) compilation and improved garbage collection (GC), replacing Dalvik that uses just-in-time (JIT) compilation Android Version And Features
  15. 15. Version Release Date Features 6.0 (Marshmallow) 17 August 2015 • Android Pay • Fingerprint Scan Standardization • App Permission Control • App Links • Doze • Home Screen Rotation • Chrome Custom Tab • Auto backup and Store • Status bar icon removal Android Version And Features
  16. 16. Android Version And Features Version Release Date Features Android N
  17. 17. Installing Software
  18. 18. Installing Android Software ● Download jdk 8 from below link http://www.oracle.com/technetwork/java/javase/downloads/ jdk8-downloads-2133151.html ● Download Android Studio from below link https://developer.android.com/studio/index.html ● Follow instruction as per installer ● Set JAVA_HOME and ANDROID_HOME environment variables
  19. 19. Installing Android Software Setting JAVA_HOME and ANDROID_HOME environment variable ● Right click windows icon and select system option
  20. 20. Installing Android Software Select Advance system settings
  21. 21. Installing Android Software Select Environment Variables
  22. 22. Installing Android Software Define JAVA_HOME and ANDROID_HOME Environment Variables
  23. 23. Android Studio Welcome Screen
  24. 24. Hello Android Example
  25. 25. Hello Android Example Summary steps to develop an Android application : ● Install Android Studio ● Create an Android Virtual Device (AVD) ● Create Android Project ● Code it… ● Start it in Android Virtual Device (AVD)
  26. 26. Hello Android Example Tools used in this tutorial : ● JDK 8 ● Android Studio 2.1
  27. 27. What is Android Studio? ● Android Studio is the official Integrated Development Environment (IDE) for Android app development, based on IntelliJ IDEA ● A flexible Gradle-based build system ● A fast and feature-rich emulator ● A unified environment where you can develop for all Android devices ● Instant Run to push changes to your running app without building a new APK
  28. 28. What is Android Studio? ● Code templates and GitHub integration to help you build common app features and import sample code ● Extensive testing tools and frameworks ● Lint tools to catch performance, usability, version compatibility, and other problems ● C++ and NDK support ● Built-in support for Google Cloud Platform, making it easy to integrate Google Cloud Messaging and App Engine
  29. 29. Android Studio – Project Structure ● A project in Android Studio contains following, one or more, modules with source code files and resource files – Android app modules – Library modules – Google App Engine modules
  30. 30. Android Studio – Project Structure ● By default, Android Studio displays project files in the Android project view ● All the build files are visible at the top level under Gradle Scripts ● Each app module contains the following folders: ● manifests: Contains the AndroidManifest.xml file ● java: Contains the Java source code files, including JUnit test code ● res: Contains all non-code resources, such as XML layouts, UI strings, and bitmap images
  31. 31. Android Studio – User interface ● Toolbar  - Running your app and launching Android tools ● Navigation bar - Navigate through your project and open files for editing ● Editor window - Create and modify code ● Tool windows - Access to specific tasks like project management, search, version control, and more ● Status bar - Displays the status of your project and the IDE itself, as well as any warnings or messages
  32. 32. Android Studio – Gradle Build ● Android Studio build files are named build.gradle ● They are plain text files that use Groovy syntax to configure the build with elements provided by the Android plugin for Gradle ● Each project has one top-level build file for the entire project and separate module-level build files for each module ● When you import an existing project, Android Studio automatically generates the necessary build files ● Build Variants ● APK Splits ● Resource Shrinking ● Managing Dependencies
  33. 33. Android Studio – Tools ● SDK Tools – Virtual Device tools – Development tools – Debugging tools – Build Tools – Image Tools ● Platform Tools – Adb – Bmgr – Logcat – Other (aidl, aapt, dexdump & dx)
  34. 34. Android Studio – Virtual Device Tools ● Android Virtual Device Manager – The AVD Manager provides a graphical user interface in which you can create and manage Android Virtual Devices (AVDs) that run in the Android Emulator ● Android Emulator (emulator) – A QEMU-based device-emulation tool that you can use to debug and test your applications in an actual Android run-time environment ● Mksdcard – Helps you create a disk image that you can use with the emulator, to simulate the presence of an external storage card (such as an SD card)
  35. 35. Android Studio – Development Tools ● Hierarchy Viewer (hierarchyviewer) – Visual representation of the layout's View hierarchy with performance information for each node in the layout – Magnified view of the display to closely examine the pixels in your layout ● SDK Manager – To manage SDK packages (platforms & system images) ● Sqlite3 – To access SQLite data files (created & used by Android apps)
  36. 36. Android Studio – Debug and Profile Tools ● Android Monitor – Is integrated into Android Studio and provides logcat, memory, CPU, GPU, and network monitors for app debugging and analysis. ● Android Debug Bridge – Lets you communicate with an emulator instance or connected Android-powered device ● ADB Shell Commands – Learn the commands available for advanced command-line operations ● Dalvik Debug Monitor Server (ddms) – Lets you debug Android apps
  37. 37. Android Studio – Debug and Profile Tools ● Device Monitor – A stand-alone tool that provides a graphical user interface for several Android application debugging and analysis tools ● systrace – To analyze the execution of app in the context of system processes, to help diagnose display & performance issues ● traceview – A graphical viewer for execution logs saved by app ● Tracer for OpenGL ES – Allows you to capture OpenGL ES commands & frame- by-frame images to help you understand how your app is executing graphics commands
  38. 38. Android Studio – Platform Tools ● Android Debug Bridge (adb) – A versatile tool that lets you manage the state of an emulator instance or Android-powered device – To install an Android app (.apk) file on a device ● Android SDK shell tools (accessed through adb) – Backup Manager (bmgr) – Logcat ● Other (aidl, aapt, dexdump and dx) – Typically called by the Android build tools, so you rarely need to invoke these tools directly – As a general rule, you should rely on the build tools to call them as needed
  39. 39. Android Architecture/Software Stack
  40. 40. Android Architecture 40
  41. 41. Architecture Detail ● Android is built on Linux 3.x kernel ● Does not include the full set of standard Linux utilities ● It has a core capability like – Security – Memory management – Process management – Network stack – Driver model – Abstraction Layer
  42. 42. Architecture Detail ● It has a core capability like: – Display Driver – Camera Driver – Bluetooth Driver – Flash Memory Driver – USB Driver – Keypad Driver – WiFi Driver – Audio Driver – Power Management
  43. 43. Libraries ● Native libraries. ● Written in C/C++ internally ● Called through Java wrapper APIs ● Layer contains – Surface Manager (for compositing windows), – 2D and 3D graphics, – Media codecs (MPEG-4, H.264, MP3, etc.), – SQL database (SQLite) and – A native web browser engine (WebKit).
  44. 44. Functional Libraries - WebKit ● Open source WebKit browser: http://webkit.org ● Renders pages in full (desktop) view ● Full CSS, Javascript, DOM, AJAX support
  45. 45. SQLite ● Server less, transactional SQL database engine. ● Most widely deployed SQL database engine in the world. ● Light-weight transactional data store ● Back end for most platform data storage ● Transactions are atomic, consistent, isolated, and durable (ACID) even after system crashes and power failures. ● Zero-configuration - no setup or administration needed. ● A complete database is stored in a single cross-platform disk file. ● Cross-platform: Unix (Linux and Mac OS X), OS/2, and Windows (Win32 and WinCE) supported.
  46. 46. Dalvik Virtual Machine
  47. 47. Dalvik Virtual Machine ● Highly optimized VM, compiled byte is optimized for mobile devices ● Register based NOT Stack based ● NOT a JVM ● End result is NOT the same byte code as Java, ● dx in the sdk takes compiled Java class files and converts them into .dex ● Built with security and performances (battery life) in mind
  48. 48. Application Framework ● Content Providers – access, store and share application data ● Resource Manager - access to strings, graphics, and layout files ● Notification Manager - Display custom alerts in the status bar ● Activity Manager - Manages the life cycle of applications ● Window Manager- rendering view on the screen ● View System – UI components ● Package Manager – Application formation ● Location Manager – Location based services
  49. 49. Application Layer ● Collection of built-in and 3rd party apps ● Built-in apps - Phone and Web Browser ● Google and 3rd party apps uses same APIs and goes through same approval process ● Built-in applications can be stopped to use 3rd party apps
  50. 50. Dalvik Runtime ● Dalvik is the virtual machine (VM) in Android OS ● Used on mobile devices such as mobile phones, tablets & netbooks. ● Android applications are converted into the compact Dalvik Executable (.dex) ● Dalvik VM is a register-based architecture. ● A tool called dx is used to convert some (but not all) Java .class files into the .dex format.
  51. 51. Dalvik Runtime ● Multiple classes are included in a single .dex file. ● As of Android 2.2, Dalvik has a just-in-time compiler. ● Being optimized for low memory requirements, Dalvik has some specific characteristics that differentiate it from other standard VMs: – The VM was slimmed down to use less space – It uses its own bytecode, not Java bytecode – Moreover, Dalvik has been designed so that a device can run multiple instances of the VM efficiently.
  52. 52. Dalvik vs JVM Dalvik Virtual machine (DVM) ● Register Architecture ● Designed to run on low memory, ● Uses its own byte code ● Runs .Dex file (Dalvik Executable File Java Virtual Machine (JVM) ● Stack Architecture ● Uses java byte code ● Runs .class file having JIT.
  53. 53. Android Runtime ● Android application == a process ● A process == an instance of the Dalvik virtual machine. ● Dalvik can run multiple VMs efficiently. ● Executes classes compiled by a Java language compiler that have been transformed into the .dex format. ● DVM executes files in the Dalvik Executable (.dex) format which is optimized.
  54. 54. Android App Building Blocks
  55. 55. Objectives At the end of this module you will be able to: ● Recognize Essential app components – Activity – Services – Broadcast Receiver – Service Provider ● Understand other app building blocks – Intent – Notifications – Resources – Manifest
  56. 56. App Building Blocks Component s Messages Resources Configurati on Activity Intent Icons App Manifest Services Notifications Strings Broadcast Receiver Content Provider
  57. 57. App Building Blocks - Activity Activities in an App “An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map” “An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map”
  58. 58. App Building Blocks - Activity ● Activity - UI component ● Activities are stacked like a deck of cards ● Only one is visible and active ● New activities are placed on top ● Examples of activities : ● List of menu items users can choose. ● Text messaging application ● List of contacts to send messages ● Each activity is independent of the others ● Each one is implemented as a subclass of the Activity base class
  59. 59. ● Each activity is given a window in which to draw its user interface ● An application usually consists of multiple activities that are loosely bound to each other ● Each activity can then start another activity in order to perform different actions ● When a new activity starts, it is pushed onto the back stack and takes user focus App Building Blocks - Activity
  60. 60. ● Each time a new activity starts, the previous activity is stopped, but the system preserves the activity in a stack (the "back stack") ● The back stack follows "last in, first out" mechanism. So, when user is done with the current activity and presses the Back button – Current activity is destroyed – Previous activity is popped from back stack and resumes ● When an activity is stopped, due to a new activity starts, it is notified of this change in state through the activity's lifecycle callback methods App Building Blocks - Activity
  61. 61. ● There are several callback methods that an activity might receive, due to a change in its state - whether the system is creating it, stopping it, resuming it, or destroying it - and each callback provides you the opportunity to perform specific work that's appropriate to that state change ● When stopped, activity should release any large objects, such as network or database connections. ● When the activity resumes, you can reacquire the necessary resources and resume actions that were interrupted. These state transitions are all part of the activity lifecycle App Building Blocks - Activity (Life Cycle)
  62. 62. Android Building Blocks - Activity (Life Cycle) Method Usage onCreate() Called when activity is created first time; activity is initialize here onStart() Called when activity becoming visible to user onResume() Called when activity starts interacting with user; at this point activity is at the top of the activity stack onPause() Called when system is about to start resuming a previous activity onStop() Called when activity is no longer visible; because another activity has been resumed and is covering this one onDestroy() Called before the activity is destroyed by the system onRestart() Called when the activity restarts after stopping it
  63. 63. App Building Blocks - Services “A Service is an application component that can perform long-running operations in the background and does not provide a user interface” “A Service is an application component that can perform long-running operations in the background and does not provide a user interface” ● Another app component can start a service and it will continue to run in the background even if the user switches to another application ● Additionally, a component can bind to a service to interact with it and even perform inter-process communication (IPC) ● Example - play music, download a file, tracking distance traveled through sensor, all from the background
  64. 64. ● Faceless task that runs in the background ● No visual user interface ● Can run indefinitely unless stopped ● Each service extends the Service base class App Building Blocks - Services
  65. 65. ● Broadcast receivers are dormant listeners that can register for various system or application events (intents) ● Static Registration - done in the manifest file using intent filters ● Dynamic Registration – done at runtime ● Local broadcast - within app components ● Global broadcast – system wide communication App Building Blocks - Broadcast Receiver “A BroadcastReceiver is an application component that responds to system-wide broadcast announcements” “A BroadcastReceiver is an application component that responds to system-wide broadcast announcements”
  66. 66. ● Broadcast can be Initiated by System and Apps ● Battery low, External power connected/disconnected, Screen on/off are example of system generated broadcasts ● SMS or Email App can broadcast that SMS or Email is received App Building Blocks - Broadcast Receiver
  67. 67. ● Normal broadcasts (sent with Context.sendBroadcast) – Completely asynchronous – All receivers of the broadcast are run in an undefined order, often at the same time – This is more efficient, but means that receivers cannot use the result or abort APIs included here ● Ordered broadcasts (sent with Context.sendOrderedBroadcast) – Delivered to one receiver at a time – As each receiver executes in turn, it can propagate a result to the next receiver, or it can completely abort the broadcast so that it won't be passed to other receivers App Building Blocks - Broadcast Receiver
  68. 68. App Building Blocks - Content Provider ● Content providers manage access to a structured set of data ● They encapsulate the data and provide mechanisms for defining data security ● Android itself includes content providers that manage data such as audio, video, images, and personal contact information ● Other examples - Calender Provider, Contacts Provider “Content providers are the standard interface that connects data in one process with code running in another process” “Content providers are the standard interface that connects data in one process with code running in another process”
  69. 69. App Building Blocks - Content Provider Content Provider Content Resolver Remote DB File Local DB Application Application Activity Activity Activity
  70. 70. ● Extends the ContentProvider base class ● An application accesses the data from a content provider with a ContentResolver client object ● Enable apps to share data ● Makes a specific set of the app's data available to other app(s) ● Date stored in file system or database (SQLite) ● Data exposed as a unique URI App Building Blocks - Content Provider
  71. 71. App Building Blocks - Intent “An intent is an abstract description of an operation to be performed” “An Intent is a messaging object you can use to request an action from another app component” “An intent is an abstract description of an operation to be performed” “An Intent is a messaging object you can use to request an action from another app component” ● It's an “Intention” to perform an action ● Provides a facility for performing late runtime binding between the code in different applications ● It is basically a passive data structure holding an abstract description of an action to be performed
  72. 72. App Building Blocks - Intent ● Intent is used to – Launch an Activity – Switch between Activities – Broadcast intent to Boradcast receiver – Start service or bind service to communicate with background service Intent Structure action The general action to be performed, such as VIEW, EDIT, MAIN, etc. data The data to operate on, such as a person record in the contacts database, expressed as URI
  73. 73. App Building Blocks - Intent ● Provides late runtime binding – Set and respond to notifications or status changes – Can wake up your app – Wakes up a predefined action through the external event ● For example: – Alarm notification, when the user receives email
  74. 74. App Building Blocks - Notifications ● A notification is a message displayed to the user outside of application's normal UI ● Notifications are issued by system through Notification Manager ● Notification first appears as an icon in the notification area ● To see details of notification, user shall opens the notification drawer ● Both the notification area and the notification drawer are system-controlled areas that the user can view at any time
  75. 75. App Building Blocks - Notifications ● Object of Notification class ● Notify the user about events ● Sent through NotificationManager ● Types – Persistent icon – Sound or vibration
  76. 76. App Building Blocks - Resources ● Always externalize resources such as images and strings from your application code, so that you can maintain them independently ● Externalizing your resources also allows you to provide alternative resources that support specific device configurations such as different languages or screen sizes ● Organized in /res project directory “Resources are the additional files and static content that your code uses, such as bitmaps, layout definitions, user interface strings, animation instructions, and more” “Resources are the additional files and static content that your code uses, such as bitmaps, layout definitions, user interface strings, animation instructions, and more”
  77. 77. App Building Blocks - Resources ● Default resources are those that should be used regardless of the device configuration or when there are no alternative resources that match the current configuration ● Alternative resources are those that you've designed for use with a specific configuration ● Example, while your default UI layout is saved in the res/layout/ directory, you might specify a different layout to be used when the screen is in landscape orientation Two different layouts for different screens
  78. 78. App Building Blocks - App Manifest ● Every application must have an AndroidManifest.xml file (with precisely that name) in its root directory ● It names the Java package for the application. The package name serves as a unique identifier for the application “The manifest file presents essential information about your app to the Android system, information the system must have before it can run any of the app's code” “The manifest file presents essential information about your app to the Android system, information the system must have before it can run any of the app's code”
  79. 79. App Building Blocks - App Manifest ● It describes the components of the application ● It determines which processes will host application components ● It declares which permissions the application must have in order to access protected parts of the API and interact with other applications ● It also declares the permissions that others are required to have in order to interact with the application's components ● It declares the minimum level of the Android API that the application requires ● It lists the libraries that the application must be linked against
  80. 80. App Building Blocks - View and ViewGroup ● All user interface elements in an Android app are built using View and ViewGroup objects ● A View is an object that draws something on the screen that the user can interact with ● A ViewGroup is an object that holds other View (and ViewGroup) objects in order to define the layout of the interface ● Views are Organized as tree to build up GUIs ● Views are Described in XML in layout resources
  81. 81. App Building Blocks - View and ViewGroup ● View Group is an invisible container that organizes child views ● Child Views may be input controls or other widgets that draw some part of the UI
  82. 82. App Building Blocks - View and ViewGroup ● Android compiles the XML layout code that is later loaded in code usually by public void onCreate(Bundle savedInstanceState) { ... setContentView(R.layout.filena me); ... }
  83. 83. App Building Blocks - View and ViewGroup ● View and ViewGroup trees build up complex GUIs ● Android framework is responsible for: – Measuring – laying out – drawing
  84. 84. Android Tools
  85. 85. Objectives At the end of this module you will be able to: ● Understand about Emulator ● Eclipse plugin ● Debugging ● DDMS
  86. 86. Emulator ● Emulator runs same system image as a device.
  87. 87. Debugging
  88. 88. DDMS
  89. 89. AndroidManifest.xml ● Starts with tag <manifest> ● uses-sdk ● uses-configuration ● uses-feature ● supports-screens ● Application ● service ● Provider ● Receiver ● Uses-permission ● Permission
  90. 90. ADB
  91. 91. Questions ● What is Android? ● What are Android Features? ● What is the difference between Dalvik and JVM?
  92. 92. User Interface
  93. 93. Agenda ● Why is UI important? ● Bad UI ● Good UI ● Application UI design philosophy ● Android UI features ● Basic android UI elements ● Tools- The Android draw tool ● Layout ● Android advanced UI
  94. 94. Why is UI important? • Better UI • Perceived quality + polish • Better rating • Better app ranking • More installs/purchases
  95. 95. Bad UI Too many views
  96. 96. Bad UI Too many colors?
  97. 97. Good UI Clear design
  98. 98. Application UI Design Philosophy • “Successful application will offer an outstanding end-user experience” • Fast • Simple • Seamless • Most iOS apps are poular because they have an outstanding UI and are fast! • The industry takes user experience seriously!
  99. 99. Android UI Features • Rich UI model, huge number of components • Code in Java or XML • Based on the MVC model • New APIs, no J2ME, AWT, Swing • Both keypad and touch modes • Support for different resolutions • Unified UI experience across device
  100. 100. Basic Android UI Elements • Views • Layouts • Shapes • Colors • Gradients
  101. 101. Basic UI components ● Button, ● ImageButton, ● CheckBox ● EditText, ● ImageView ● TextView ● ListMenuItemView ● RadioButton ● RadioGroup
  102. 102. Basic UI Component ● Progress Bar
  103. 103. Zoom Slider ● Zoom Slider
  104. 104. ListView ● ListView
  105. 105. ScrollView ● ScrollView
  106. 106. Toast Toast.makeText(getApplicationC ontext(),"Button is clicked", Toast.LENGTH_LONG).show();
  107. 107. Toggle Button <ToggleButton android:id="@+id/togglebutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textOn="Vibrate on" android:textOff="Vibrate off" android:onClick="onToggleClicked"/>
  108. 108. Switch Button <Switch android:id="@+id/mySwitch" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginTop="20dp" android:text="Play with the Switch" />
  109. 109. Alert Dialog
  110. 110. Spinner <Spinner android:id="@+id/ spinner2" android:layout_wid th="match_parent" android:layout_hei ght="wrap_conten t" />
  111. 111. Auto Complete TextView <AutoCompleteTextView android:id="@+id/autoCompleteText View1" android:layout_width="wrap_content" android:layout_height="wrap_content " android:layout_alignParentTop="true" android:layout_centerHorizontal="tru e" android:layout_marginTop="65dp" android:ems="10" > <requestFocus /> </AutoCompleteTextView>
  112. 112. Rating Bar <RatingBar android:id="@+id/ratingBar " android:layout_width="wrap _content" android:layout_height="wra p_content" android:numStars="4" android:stepSize="1.0" android:rating="2.0" />
  113. 113. Date Picker <DatePicker android:id="@+id/dpResult" android:layout_width="wrap _content" android:layout_height="wra p_content" />
  114. 114. Time Picker <TimePicker android:id="@+id/timePicke r1" android:layout_width="wrap _content" android:layout_height="wra p_content" />
  115. 115. Quick Contact Budge QuickContactBadge badgeSmall = (QuickContactBadge) findViewById(R.id.badge_sm all); badgeSmall.assignContactFr omEmail("any@gmail.com", true); badgeSmall.setMode(Contac tsContract.QuickContact.MO DE_SMALL);
  116. 116. Analog Clock and Digital Clock ● AnalogClock ac = (AnalogClock) findViewById(R.id.analogClo ck1); ● DigitalClock dc = (DigitalClock) findViewById(R.id.digitalClo ck1);
  117. 117. Two UI Approaches You can mix and match both styles. Declarative is preferred: easier and more tools Code XML You write Java code Similar to Swing or AWT You write XML code Similar to HTML of a web page
  118. 118. Draw Tool 1 1 8
  119. 119. Activity, Intent & Fragment
  120. 120. What is Activity ● An activity is a single, focused thing that the user can do. ● Almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI.
  121. 121. Life Cycle of Activity
  122. 122. Android Activity Life Cycle Example
  123. 123. Intent ● Implicit Intent ● Explicit Intent
  124. 124. Intent
  125. 125. Intent
  126. 126. Intent ● Implicit Intent ● Explicit Intent
  127. 127. Intent Methods ● Intent intent=new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://www.google.com")); startActivity(intent); //implicit ● Intent i = new Intent(getApplicationContext(), ActivityTwo.class); startActivity(i); // explicit
  128. 128. Fragments ● A Fragment represents a behavior or a portion of user interface in an Activity. ● You can combine multiple fragments in a single activity to build a multi-pane UI and reuse a fragment in multiple activities.
  129. 129. Fragments
  130. 130. Fragments
  131. 131. Fragment Life Cycle
  132. 132. Fragment Example
  133. 133. Dynamic Fragments
  134. 134. Android Menu
  135. 135. Option Menu
  136. 136. Context Menu
  137. 137. Pop Up Menu
  138. 138. Layout Manager
  139. 139. Layouts ● Layout Managers are extensions of the ViewGroup class ● Control the position of child controls on a screen. ● Versatile layout classes available: ● Relative Layout ● Linear Layout ● Table Layout ● Grid Layout
  140. 140. Activities
  141. 141. Android Activity • Basic unit of an Android application is an Activity. • May contain widgets like buttons, labels, text boxes, etc.
  142. 142. Android Activity Flow ● Load the XML UI in the onCreate() using the setContentView() ● Each element in the XML file is compiled into its equivalent Android GUI class. ● UI of the Activity created when it is loaded. ● Easier to build your UI using a XML file.
  143. 143. Attributes Attribute Description layout_widthSpecifies the width of the View or ViewGroup layout_heightSpecifies the height of the View or ViewGroup layout_marginTopSpecifies extra space on the top side of the View or ViewGroup layout_marginBottomSpecifies extra space on the bottom side of the View or ViewGroup layout_marginLeftSpecifies extra space on the left side of the View or ViewGroup layout_marginRightSpecifies extra space on the right side of the View or ViewGroup layout_gravitySpecifies how child Views are positioned layout_weightSpecifies how much of the extra space in the layout to be allocated to the View layout_xSpecifies the x-coordinate of the View or ViewGroup layout_ySpecifies the y-coordinate of the View or ViewGroup
  144. 144. Linear Layouts ● The LinearLayout arranges views in a single column or single row. ● Child views can either be arranged vertically or horizontally.
  145. 145. Linear Layout
  146. 146. Linear Layout <?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="horizontal" > </LinearLayout>
  147. 147. Relative Layout
  148. 148. Relative Layout <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android " android:layout_width="fill_parent" android:layout_height="fill_parent" > </RelativeLayout>
  149. 149. Table Layout <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas .android.com/apk/res/android" android:id="@+id/tableLayout 1" android:layout_width="fill_par ent" android:layout_height="fill_par ent" >
  150. 150. Grid View Layout <GridView xmlns:android="http://schemas.android. com/apk/res/android" android:id="@+id/gridview" android:layout_width="match_parent" android:layout_height="match_parent" android:columnWidth="90dp" android:numColumns="auto_fit" android:verticalSpacing="10dp" android:horizontalSpacing="10dp" android:stretchMode="columnWidth" android:gravity="center" />
  151. 151. Adapter
  152. 152. Adaptor ● Array Adaptor ● ArrayList Adaptor ● Base Adaptor
  153. 153. Array Adaptor ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.rowlayout, R.id.label, values); setListAdapter(adapter)
  154. 154. View
  155. 155. Grid View Web View Scroll View Search View Tab Host Dynamic List View Expanded List View View
  156. 156. Grid View
  157. 157. Web View
  158. 158. Scroll View
  159. 159. Search View
  160. 160. Tab Host
  161. 161. Dynamic ListView
  162. 162. Expandable ListView
  163. 163. Services
  164. 164. Objectives ● What is a Service? ● Service lifecycles ● Permissions ● Local services ● Remote services 164
  165. 165. When a Service Used? ● Applications will need to run processes for a long time without any intervention from the user, or very rare interventions. ● These background processes need to keep running even when the phone is being used for other activities / tasks. ● Functionality that should run invisibly, without a user interface. 165
  166. 166. ● Services gets higher priority than inactive Activities, so they’re less likely get to be killed. ● Services run without a dedicated GUI, but still execute in the main thread of the application’s process. ● Updating Content Providers ● Firing Intents ● Triggering Notifications. When a Service Used?
  167. 167. Two Types of Services ● Local service ● Not accessible from other applications ● Runs in the same process of the application that starts it ● Remote service ● Accessible from other applications as well ● Exposes to other applications through AIDL ( s Definition Language) 167
  168. 168. Service and Notification ● Service is a long lived component and does not implement any user interface of its own. ● Typically a user interacts with a service through an activity that has a UI. ● The service “notifies” the user in case of any need for user intervention. ● Through the notification (such as status bar notification), the service can give a user interface for binding to the service or viewing the status of the service or any other similar interaction with the service. 168
  169. 169. Creating a Service ● To define a Service, create a new class that extends Service. You’ll need to override onBind and onCreate, import android.app.Service; import android.content.Intent; import android.os.IBinder; public class MyService extends Service { @Override public void onCreate() { // TODO: Actions to perform when service is created. } @Override public IBinder onBind(Intent intent) { // TODO: Replace with service binding implementation. return null; } }
  170. 170. Controlling Services ● Override onStartCommand(). ● Is called whenever the Service is started with a call to startService, so it may be executed several times within a Service’s lifetime. ● onStartCommand it enables you to tell the system how to handle restarts if the Service is killed by the system prior to an explicit call to stopService or stopSelf. ● Services are launched on the main Application thread ● Any processing done in the onStartCommand handler will happen on the main GUI thread. @Override public int onStartCommand(Intent intent, int flags, int startId) { // TODO Launch a background thread to do processing. return Service.START_STICKY; } 170
  171. 171. What Facilities Service Provide? ● A facility for the application to tell the system about something it wants to be doing in the background (even when the user is not directly interacting with the application). ● This corresponds to calls to Context.startService(),which ask the system to schedule work for the service, to be run until the service or someone else explicitly stop it. ● A facility for an application to expose some of its functionality to other applications. ● This corresponds to calls to Context.bindService(),which allows a long-standing connection to be made to the service in order to interact with it.
  172. 172. Binding to a Service ● Once a service has begun and is running in the background, activities can “bind” to the service. ● In fact, if we want to bind to a service that has not started, calling to bind could initiate the service. 172
  173. 173. What Facilities Service Provide? ●A facility for the application to tell the system about something it wants to be doing in the background (even when the user is not directly interacting with the application). ●This corresponds to calls to Context.startService(),which ask the system to schedule work for the service, to be run until the service or someone else explicitly stop it.
  174. 174. What Facilities Service Provide? ● A facility for an application to expose some of its functionality to other applications. ● This corresponds to calls to Context.bindService(),which allows a long-standing connection to be made to the service in order to interact with it.
  175. 175. Starting a Service ● If someone calls Context.startService() then the system will retrieve the service (creating it and calling its onCreate() method if needed) and then call its onStartCommand(Intent, int, int) method with the arguments supplied by the client. ● The service will at this point continue running until Context.stopService() or stopSelf() is called.
  176. 176. Modes of Operations For started services, there are two additional major modes of operation they can decide to run in, depending on the value they return from onStartCommand(): ● START_STICKY is used for services that are explicitly started and stopped as needed, ● START_NOT_STICKY or START_REDELIVER_INTENT are used for services that should only remain running while processing any commands sent to them. 176
  177. 177. Getting a Connection to a Service ● Clients can also use Context.bindService() to obtain a persistent connection to a service. ● This likewise creates the service if it is not already running (calling onCreate() while doing so), but does not call onStartCommand() ● The client will receive the IBinder object that the service returns from its onBind(Intent) method, allowing the client to then make calls back to the service.
  178. 178. 178 Permissions ● Global access to a service can be enforced when it is declared in its manifest's <service> tag. ● By doing so, other applications will need to declare a corresponding <uses-permission> element in their own manifest to be able to start, stop, or bind to the service. ● In addition, a service can protect individual IPC calls into it with permissions, by calling the checkCallingPermission(String) method before executing the implementation of that call.
  179. 179. Local Service ● One of the most common uses of a Service is as a secondary component running alongside other parts of an application, in the same process as the rest of the components. ● All components of an .apk run in the same process unless explicitly stated otherwise, so this is a typical situation. ● When used in this way, by assuming the components are in the same process, you can greatly simplify the interaction between them. ● Clients of the service can simply cast the Ibinder they receive from it to a concrete class published by the service. 179
  180. 180. Remote Messenger Service ● If you need to be able to write a Service that can perform complicated communication with clients in remote processes (beyond simply the use of Context.startService to send commands to it), then you can use the Messenger class instead of writing full AIDL files.
  181. 181. Preferences
  182. 182. ● The SharedPreferences class provides a general framework that allows you to save and retrieve persistent key-value pairs of primitive data types. ● You can use SharedPreferences to save any primitive data: booleans, floats, ints, longs, and strings. This data will persist across user sessions (even if your application is killed). 182 SharedPreferences
  183. 183. ● To get a SharedPreferences object for your application, use one of two methods: ● getSharedPreferences() - Use this if you need multiple preferences files identified by name, which you specify with the first parameter. ● getPreferences() - Use this if you need only one preferences file for your Activity. Because this will be the only preferences file for your Activity, you don't supply a name. 183 SharedPreferences
  184. 184. ● To write values: ● Call edit() to get a SharedPreferences.Editor. Add values with methods such as putBoolean() and putString(). Commit the new values with commit() SharedPreferences
  185. 185. ● getFilesDir() ● Gets the absolute path to the filesystem directory where your internal files are saved. ● getDir() ● Creates (or opens an existing) directory within your internal storage space. ● deleteFile() ● Deletes a file saved on the internal storage. ● fileList() ● Returns an array of files currently saved by your application. 185 Other Useful Methods
  186. 186. Data Storage
  187. 187. ● Android Database ● SQLite Database ● Content Providers ● Cursors and Content Values ● SQLiteOpenHelper ● Querying a Database ● Add, Update, Delete records ● Access DB through command line ● SQLite database file 187 Agenda
  188. 188. Structured data persistence in Android : ● SQLite Databases : Offers the SQLite relational database library ● Content Providers: offer a generic, well-defined interface for using and sharing data between applications 188 Android Databases
  189. 189. ● Independent relational databases for applications. ● Store and manage complex, structured application data. ● DB stored in the /data/data/<package_name>/databases folder on your device (or emulator). 189 SQLite Databases
  190. 190. ● All databases are private. Standard database best practices apply in Android. ● Normalize your data to reduce redundancy. SQLite Databases
  191. 191. ● SQLite has a reputation for being extremely reliable and is the database system of choice for many : ● Consumer electronic devices ● Including several MP3 players ● iPhone, and the iPod Touch. SQLite
  192. 192. ● SQLite is a well regarded relational database management system (RDBMS). It is: Open-source Standards-compliant Lightweight Single-tier C library ● SQLite database is an integrated part of the application. 192 SQLite
  193. 193. ● SQLite has a reputation for being extremely reliable and is the database system of choice for many : ● Consumer electronic devices ● Including several MP3 players ● iPhone, and the iPod Touch. SQLite
  194. 194. ●ContentValues used to insert new rows into tables. ●Queries in Android returned as Cursor objects. ●The startManagingCursor method integrates the Cursor’s lifetime into the calling Activity’s.When you’ve finished with the Cursor, call stopManagingCursor to do just that. 194 Cursors And Content Values
  195. 195. Navigation functions including: ● moveToFirst Moves the cursor to the first row in the query result ● moveToNext Moves the cursor to the next row ● moveToPrevious Moves the cursor to the previous row ● getCount Returns the number of rows in the result set ● getColumnName Returns the name of the specified column index ● moveToPosition Moves the Cursor to the specified row ● getPosition Returns the current Cursor position Cursors And Content Values
  196. 196. ● SQLiteOpenHelper is an abstract class : ● Used for creating, ● Opening, and upgrading databases. ● onCreate, and onUpgrade - creation of a new database. ● Create a new instance ● Passing in the context ● Database name ● Current version ● Call getReadableDatabase or getWritableDatabase to open and return a readable/writable instance of the underlying database. 196 SQLiteOpenHelper
  197. 197. 197 SQLiteOpenHelper dbHelper = new myDbHelper(context, DATABASE_NAME, null, DATABASE_VERSION); SQLiteDatabase db; try { db = dbHelper.getWritableDatabase(); } catch (SQLiteException ex) { db = dbHelper.getReadableDatabase(); }
  198. 198. Opening and creating databases without SQLiteHelper: ● Create and open databases by using the openOrCreateData base method from the application Context. ● Setting up a database is a two-step process: – call openOrCreateDatabase to create the new database. – call execSQL to run the SQL commands 198 Opening And Creating Databases
  199. 199. private static final String DATABASE_NAME = "myDatabase.db"; private static final String DATABASE_TABLE = "mainTable"; private static final String DATABASE_CREATE = "create table " + DATABASE_TABLE + " ( _id integer primary key autoincrement," + "column_one text not null);"; SQLiteDatabase myDatabase; private void createDatabase() { myDatabase = openOrCreateDatabase(DATABASE_NAME, Context.MODE_PRIVATE, null); myDatabase.execSQL(DATABASE_CREATE); } 199 Opening And Creating Databases Without SQLiteHelper
  200. 200. ● Database query returns a Cursor. ● To execute needs : – Optional Boolean – if result set should contain only unique values. – The name of the table to query. – Lists the columns to include in the result set. – ‘‘where’’ clause – Defines the rows to be returned. – A ‘‘group by’’ clause that defines how the resulting rows will be grouped. – A ‘‘having’’ filter that defines which row groups to include if you specified a group by clause. – Describes the order of the returned rows. – Limit the number of returned rows. 200 Querying A Database
  201. 201. // Return all rows for columns one and three, no duplicates String[] result_columns = new String[] {KEY_ID, KEY_COL1, KEY_COL3}; Cursor allRows = myDatabase.query(true, DATABASE_TABLE, result_columns, null, null, null, null, null, null); // Return all columns for rows where column 3 equals a set value // and the rows are ordered by column 5. String where = KEY_COL3 + "=" + requiredValue; String order = KEY_COL5; Cursor myResult = myDatabase.query(DATABASE_TABLE, null, where, null, null, null, order); 201 Querying A Database
  202. 202. ● First use the moveTo<location> methods described earlier to position the cursor at the correct row of the result Cursor. String columnValue = myResult.getString(columnIndex); 202 Extracting Results From Cursor
  203. 203. int GOLD_HOARDED_COLUMN = 2; Cursor myGold = myDatabase.query("GoldHoards", null, null, null, null, null, null); float totalHoard = 0f; // Make sure there is at least one row. if (myGold.moveToFirst()) { // Iterate over each cursor. do { float hoard = myGold.getFloat(GOLD_HOARDED_COLUMN); totalHoard += hoard; } while(myGold.moveToNext()); } float averageHoard = totalHoard / myGold.getCount(); 203 Extracting Results From Cursor
  204. 204. // Create a new row of values to insert. ContentValues newValues = new ContentValues(); // Assign values for each row. newValues.put(COLUMN_NAME, newValue); [ ... Repeat for each column ... ] // Insert the row into your table myDatabase.insert(DATABASE_TABLE, newValues); ● Construct a ContentValues object ● Put methods to provide a value for each column. 204 Inserting New Rows
  205. 205. // Define the updated row content. ContentValues updatedValues = new ContentValues(); // Assign values for each row. newValues.put(COLUMN_NAME, newValue); [ ... Repeat for each column ... ] String where = KEY_ID + "=" + rowId; // Update the row with the specified index with the new values. myDatabase.update(DATABASE_TABLE, newValues, where, null); 205 Updating A Row
  206. 206. myDatabase.delete(DATABASE_TABLE, KEY_ID + "=" + rowId, null); 206 Deleting Rows
  207. 207. Content Providers
  208. 208. ● Content providers store and retrieve data and make it accessible to all applications.They're the only way to share data across applications ! ● Content providers provide a level of abstraction for any data stored on the device that is accessible by multiple applications Content Provider Intended Data Browser Browser bookmarks, browser history, etc. CallLog Missed calls, call details, etc Contacts Contact details MediaStore Media files such as audio, video and images Settings Device settings and preferences 208 Content Provider
  209. 209. ● Create, retrieve, update, delete data of a particular type ● Exposes URI for each data set ● Content resolver ● given URI, create, retrieve, update and delete data ● Table model ● Cursor, ContentValues         ContentResolver content = getContentResolver();         Cursor cursor = content.query(Contacts.People.CONTENT_URI,                 PEOPLE_PROJECTION, null, null, Contacts.People.DEFAULT_SORT_ORDER); 209 Content Provider
  210. 210. 210 Content Provider
  211. 211. Content Provider URI ● A Content Provider exposes a unique URI used to query, add, update and delete data: – Standard prefix (“content://”) – The authority part, it identifies the content provider – To determine what kind of data is being requested – The ID of the specific record being requested 211
  212. 212. ● Use the existing content provider as is. ● Modify the existing content provider [based on the requirement]. ● Write a completely new content provider. 212 Ways of Using Content Provider
  213. 213. ● To create a new Content Provider, extend the abstract ContentProvider class. ● Override the onCreate method to create (and initialize) the underlying data source you’re planning to publish with this provider. 213 Creating a New Content Provider
  214. 214. import android.content.*; import android.database.Cursor; import android.net.Uri; import android.database.SQLException; public class MyProvider extends ContentProvider { @Override public boolean onCreate() { // TODO Construct the underlying database. return true; } } Creating a New Content Provider
  215. 215. ● You should expose a public static CONTENT_URI property that returns the full URI of this provider. ● A Content Provider URI must be unique to the provider, so it’s good practice to base the URI path on your package name. The general form for defining a Content Provider’s URI is: content://com.<CompanyName>.provider.<ApplicationName>/<Data Path> 215 Content Provider URI
  216. 216. ● Content URIs can represent either of two forms: - URI represents a request for all values - A trailing /<rownumber>, represents a request for a single record ● It’s good practice to support access to your provider for both of these forms. content://com.emertxe.provider.myapp /elements content://com.emertxe.provider.myapp/elements/ 5 Content Provider
  217. 217. ● Once you have completed your Content Provider, it must be added to the application manifest. ● Use the authorities tag to specify its base URI, as shown in the following XML snippet. <provider android:name="MyProvider" android:authorities="com.paad.provider.myapp"/> 217 Registering Your Provider
  218. 218. ● Content Resolver includes a number of methods to modify and query Content Providers. ● Each method accepts a URI that specifies the Content Provider to interact with. ● A Content Provider’s URI is its authority as defined by its manifest node. ContentResolver cr = getContentResolver(); 218 Content Resolvers
  219. 219. ContentResolver cr = getContentResolver(); // Return all rows Cursor allRows = cr.query(MyProvider.CONTENT_URI, null, null, null, null); // Return all columns for rows where column 3 equals a set value // and the rows are ordered by column 5. String where = KEY_COL3 + "=" + requiredValue; String order = KEY_COL5; Cursor someRows = cr.query(MyProvider.CONTENT_URI, null, where, null, order); 219 Content Resolvers
  220. 220. ● Content Provider queries take a form very similar to that of database queries. ● Query results are returned as Cursors over a result set ● Using the query method on the ContentResolver object, pass in: – The URI of the Content Provider data you want to query. – Lists the columns you want to include in the result set. – A where clause that defines the rows to be returned. – order of the returned rows. 220 Querying for Content
  221. 221. ● Media Store is a managed repository of audio, video, and image files. ● Whenever you add a new multimedia file to the file system, it should also be added to the Media Store. ● This will expose it to other applications, including the default media player. ● The MediaStore class includes Audio, Video, and Images subclasses, which in turn contain subclasses that are used to provide the column names and content URIs for each media provider. 221 Using the Media Storage Provider
  222. 222. ● The Media Store segregates media kept on the internal and external volumes of the host device. ● Each of the Media Store subclasses provides a URI for either the internally or externally stored media using the forms: ● MediaStore.<mediatype>.Media.EXTERNAL_CONTE NT_URI ● MediaStore.<mediatype>.Media.INTERNAL_CONTE NT_URI Using the Media Storage Provider
  223. 223. Android Multimedia
  224. 224. Android Multimedia
  225. 225. Live Wallpaper
  226. 226. Audio And Video
  227. 227. Playing Audio In Android
  228. 228. Playing Video in Android
  229. 229. Android Alarm Manager
  230. 230. Android Gallery
  231. 231. Android Speech API
  232. 232. Android Speech API ● Text to Speech ● Speech to Text
  233. 233. Android Telephony API
  234. 234. Android Telephony Manager
  235. 235. Telephony Manager Example ● Example of TelephonyManager that prints information of the telephony services. ● Determining whether phone is ringing or phone is in a call or phone is neither ringing nor in a call. ● Creating a basic android app that speaks the incoming number while phone is in ringing mode. ● Making a phone call in android via intent. ● Making a phone to send SMS and Email
  236. 236. Location and Maps
  237. 237. Android Location API
  238. 238. Google Maps
  239. 239. Android Device Connectivity
  240. 240. Agenda ● How to connect to the Wifi service ● Scanning all available wifi networks ● Bluetooth Services ● How to connect to a bluetooth adapter 240
  241. 241. Wifi Service
  242. 242. Connecting to the Wifi Service ● To define a Service, create a new class that extends Service. You’ll need to override onBind and onCreate, WifiManager wifi; wifi=(WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo info-wifi.getConnectionInfo(); List<WifiConfiguration> configs=wifi.getConfiguredNetworks(); 242
  243. 243. Sample Code to Scan Wifi Networks WifiManager wifi; wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifi.getConnectionInfo(); textStatus.append("nnWiFi Status: " + info.toString()); List<WifiConfiguration> configs = wifi.getConfiguredNetworks(); for (WifiConfiguration config : configs) { textStatus.append("nn" + config.toString()); } wifi.startScan(); 243
  244. 244. Register a Broadcast Receiver if (receiver == null) receiver = new WiFiScanReceiver(this); registerReceiver(receiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
  245. 245. In the Broadcast Receiver In the onReceive method(): List<ScanResult> results = wifiDemo.wifi.getScanResults(); //wifiDemo is the original class ScanResult bestSignal = null; for (ScanResult result : results) { if (bestSignal == null || WifiManager.compareSignalLevel(bestSignal.level, result.level)<0) bestSignal = result; } 245
  246. 246. Permissions ● Global access to a service can be enforced when it is declared in its manifest's <service> tag. ● By doing so, other applications will need to declare a corresponding <uses-permission> element in their own manifest to be able to start, stop, or bind to the service. ● < uses-permission android:name="android.permission.ACCESS_WIFI_STATE" / > ● < uses-permission android:name="android.permission.UPDATE_DEVICE_STATS"/ > ● < uses-permission android:name="android.permission.CHANGE_WIFI_STATE" / > 246
  247. 247. Questions ● Create a program that will scan all available wifi networks and display it on the screen ● When you click a scan button, it will scan the networks again and display the updated results on the screen ● Use the concept of BroadcastReceiver to update the screen once the scan is complete 247
  248. 248. Bluetooth
  249. 249. Bluetooth Adapter ● Represents the local Bluetooth adapter (Bluetooth radio). ● The BluetoothAdapter is the entry-point for all Bluetooth interaction. ● Using this, you can discover other Bluetooth devices, query a list of bonded (paired) devices, instantiate a BluetoothDevice using a known MAC address, and create a BluetoothServerSocket to listen for communications from other devices. 249
  250. 250. Bluetooth Socket ● Represents the interface for a Bluetooth socket (similar to a TCP Socket). ● This is the connection point that allows an application to exchange data with another Bluetooth device via InputStream and OutputStream. 250
  251. 251. Bluetooth Server Socket ● Represents an open server socket that listens for incoming requests (similar to a TCP ServerSocket). ● In order to connect two Android devices, one device must open a server socket with this class. ● When a remote Bluetooth device makes a connection request to the this device, the BluetoothServerSocket will return a connected BluetoothSocket when the connection is accepted. 251
  252. 252. Bluetooth Class ● Describes the general characteristics and capabilities of a Bluetooth device. ● This is a read-only set of properties that define the device's major and minor device classes and its services. ● However, this does not reliably describe all Bluetooth profiles and services supported by the device, but is useful as a hint to the device type. 252
  253. 253. Connecting to the Bluetooth Adapter 253 ● Here you must get a BluetoothAdapter and then enable bluetooth. 1. Get BluetoothAdapter BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter == null) {     // Device does not support Bluetooth } 2. Enable bluetooth if (!mBluetoothAdapter.isEnabled()) {     Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);     startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); }
  254. 254. Android Camera
  255. 255. Android Camera Android provides the facility to work on camera by 2 ways: ● By Camera Intent ● By Camera API
  256. 256. Android Sensors
  257. 257. Android Sensor Types of Sensors: ● Motion Sensor ● Position Sensor ● Environmental Sensor
  258. 258. Stay connected About us: Emertxe is India’s one of the top IT finishing schools & self learning kits provider. Our primary focus is on Embedded with diversification focus on Java, Oracle and Android areas Emertxe Information Technologies, No-1, 9th Cross, 5th Main, Jayamahal Extension, Bangalore, Karnataka 560046 T: +91 80 6562 9666 E: training@emertxe.com https://www.facebook.com/Emertxe https://twitter.com/EmertxeTweet https://www.slideshare.net/EmertxeSlides
  259. 259. Thank You

×