SlideShare ist ein Scribd-Unternehmen logo
1 von 71
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved.
Connected world
in android
Local data sharing and
service discovery
Presented by:
Kaushal Dhruw
Naval Barthwal
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 2
About PMD
• Started in August 2013
• “Increase awareness of fast growing mobile
technology among Developers”
• Currently has 3000+ members
• 21 meetups so far
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 3
Team
• Ashutosh
• Tarun
• Arvind
• Kaushal
• Suyash
• Vijendra
• Talentica Mobile Community
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 4
Agenda
 Network interfaces.
 Basic socket communication.
 Network service discovery.
 Wi-Fi direct.
 Wi-Fi direct service discovery.
 Bluetooth low energy (BLE).
 Demos (wherever needed)
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 5
Introduction
Network interfaces
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 6
Network interface
 A Network interface is a point of interconnection between a device and a public or
private network.
 It can be a hardware (Network interface card).
 Or can be implemented in software.
 Some network interfaces:
 wlan: wireless networking interface.
 lo: loopback interface (localhost, usually 127.0.0.1).
 rmnet: usually associated with mobile data and USB tethering.
 p2p: a peer-to-peer interface.
 eth, en: Ethernet card interface.
 dummy: alternative for loopback interfaces.
NetworkInterface.getNetworkInterfaces() //gets list of all available network
interfaces
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 7
Network interface methods
 isUp(): Whether the network interface is up and running.
 isVirtual(): Whether the network interface is virtual or sub-
interface.
 getSubInterfaces(): gets all the sub interfaces bound to this
network interface (like eth0:1 for eth0)
 supportsMulticast(): checks multicast support.
 getInetAddresses(): get all the addresses bound to this network
interface.
 getHardwareAddress(): usually MAC.
 getByName():
 getByInetAddress():
 getByIndex():
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 8
Network interface selection
 When a socket is created it automatically determines which
network (that is currently up and running) to use.
 Most of the times you will not have to worry about the
network interface.
 When you want to use the address of a particular network
interface, use the get methods discussed in previous slide.
 To listen to all the network interfaces, bind your socket to
“0.0.0.0”
 Loopback and dummy interfaces are used for localhost
connection testing.
 use adb shell ifconfig to list all available network interfaces.
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 9
Agenda
 Network interfaces.
 Basic socket communication.
 Network service discovery.
 Wi-Fi direct.
 Wi-Fi direct service discovery.
 Bluetooth low energy (BLE).
 Demos (wherever needed)
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 10
Generic java not specific to android
Basic socket communication
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 11
Basic socket communication
 A socket is basically an end point for two-way communication link between two devices.
 In a typical client-server architecture.
 Server runs on a specific computer and has a socket that is bound to a specific port, the
server listens for a client to make connection request in that socket.
 Client knows the host name of server and port it is listening on. The client system usually
assigns a port to rendezvous with server’s machine and port.
 Client receives confirmation of connection acceptance and can use the socket for
communicating with server.
 Listening on a port for client requests is done via ServerSocket. A ServerSocket class
provides a system independent implementation of the server side of client/server socket
connection.
ServerSocket serverSocket = new ServerSocket(port);
Socket s = serverSocket.accept();
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 12
Basic socket communication contd…
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 13
Steps involved in socket
communication
 Create a ServerSocket. This socket waits for a connection from a client on a specified
port and blocks until it happens, so do this in a background thread.
 Create a client Socket. The client uses the IP address and port of the server socket to
connect to the server device.
 Send data from the client to the server. When the client socket successfully connects to
the server socket, you can send data from the client to the server with byte streams.
 The server socket waits for a client connection (with the accept() method). This call
blocks until a client connects, so call this in another thread. When a connection
happens, the server device can receive the data from the client.
 And carry out any actions with this data, such as saving it to a file or presenting it to the
user.
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 14
Client/server sockets
ServerSocket mServer = new
ServerSocket(mPort);
While(true){
Socket s = mServer.accept();
//process s and streams and
return response if required
}
socket = new Socket(host, port);
OutputStream outputStream =
socket.getOutputStream();
ObjectOutputStream oos = new
ObjectOutputStream(outputStream);
oos.writeObject(transferObject);
oos.close();
Server Client
mPort = (new ServerSocket(0)).getLocalPort()
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 15
Use case we are solving (Local chat)
Share files
&
Send chat
&
Receive chat and file from other
devices
Share files
&
Send chat
&
Receive chat and file from other
devices
Device 1 Device 2
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 16
Agenda
 Network interfaces.
 Basic socket communication.
 Network service discovery.
 Wi-Fi direct.
 Wi-Fi direct service discovery.
 Bluetooth low energy (BLE).
 Demos (wherever needed)
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 17
Discover services and devices in the same
network
Network service discovery
(NSD)
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 18
Network service discover (NSD)
 android.net.nsd.* package is used.
 It helps with many use cases like file sharing, multi-player games etc.
 Android network service discovery allows your app to identify other
devices in the same network that support the services your app
requests.
 NSD allows us to register our service(s) on the network, discover it, and
connect with it.
 Important classes:
 NsdManager
 NsdServiceInfo
 Although internet is not used, INTERNET permission is required for
socket communication.
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 19
Basic steps in NSD
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 20
NSD Service registration
Creating NsdServiceInfo Object
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 21
NSD Service registration Listener
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 22
NSD Service discovery
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 23
NSD Service discovery Listener
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 24
Resolving discovered NSD service
• NsdManager.ResolveListener
Note**: Do not forget to stop discovery and unregister service when app closes
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 25
NSD Demo
plus code walkthrough
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 26
Agenda
 Network interfaces.
 Basic socket communication.
 Network service discovery.
 Wi-Fi direct.
 Wi-Fi direct service discovery.
 Bluetooth low energy (BLE).
 Demos (wherever needed)
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 27
Connect with devices in vicinity (Wi-Fi p2p in
android)
Wi-Fi direct
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 28
Wi-Fi direct
 Wi-Fi direct is a Wi-Fi certified standard enabling devices to
connect with each other without requiring a wireless access point.
 Using this devices can communicate with each other at typical
Wi-Fi speeds, unlike ad-hoc wireless connections (which allows
two or more devices to connect and communicate, and has a
limit of 11Mbps).
 And Wi-Fi direct has much simpler setup that ad-hoc network.
 Wi-Fi direct assigns each member a limited access point (if it is
Wi-Fi direct enabled).
 Wi-Fi direct uses WPS and WPA2 to prevent unauthorized access
and keep communications private.
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 29
Wi-Fi direct contd…
 Wi-Fi direct allows devices to connect to each other and form groups. Not
only one-to-one, but also one-to-many.
 Compatible devices negotiate their roles in the connection:
 One of these assumes role of a traditional access point. Called Group Owner (GO).
 Other devices including non-Wi-Fi direct devices connect to the Group owner or
Access point as P2P clients.
 Any P2P device can assume the role of a Group owner and P2P client. The
purpose of role negotiation is to determine which of the peer devices will
exchange group characteristics (like operating channel, WPS configuration, is
the group persistent etc.).
 Devices can communicate their willingness to become group owner with the
GO intent attribute (0-15).
 After the role negotiation a confirmation is sent and devices move to their
specified roles. GO starts operating in Access point mode.
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 30
Wi-Fi direct and android
 Android’s Wi-Fi P2P framework complies with the Wi-Fi direct certification
program. It allows devices running android 4.0+ (API 14+) with appropriate
hardware to connect easily without an intermediate access point.
 Android Wi-Fi P2P API consists of:
 Methods that allows us to discover, request and connect to peers
(android.net.wifi.p2p.WifiP2pManager).
 Listeners that notifies us of success and failure of WifiP2pmanager’s method calls.
 Intents to notify specific events, such as new peer joined, connection dropped etc.
(like WIFI_P2P_PEERS_CHANGED_ACTION and
WIFI_P2P_CONNECTION_CHANGED_ACTION)
 A single call to WifiP2pManager’s discover peers is enough for Wi-Fi direct
peer discovery. Connection however with Wi-Fi direct group requires user’s
consent. This is unlike NSD.
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 31
Wi-Fi direct – Permissions
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 32
Wi-Fi direct – starting peer
discovery
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 33
Wi-Fi direct – getting peer list
This broadcast receiver needs to be registered dynamically. It notifies when peer list has
changed so peer list can be requested from WifiP2pManager
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 34
Wi-Fi direct – getting peer list
contd…
When WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION is received in the broadcast
receiver, peer list can be requested. With WifiP2pManager.requestPeers() method.
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 35
Wi-Fi direct – WifiP2pDevice
Important method in WifiP2pDeviceList is getDeviceList() which gives a collection of
WifiP2pDevice, it has the following important fields
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 36
Wi-Fi direct – Connecting to a
peer
Once a peer is discovered, connection request can be sent
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 37
Connecting to a peer –
WifiP2pInfo
Once connection is successful a connection info request can be issued via WifiP2pManager.
Which send callback to WifiP2pManager.ConnectionInfoListener. It has only one method
described below:
WifiP2pInfo 
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 38
WifiP2pManager - createGroup
 This method is to support older devices that do not support Wi-Fi direct. It creates
an Access point which non-Wi-Fi direct can connect to (like a regular Wi-Fi), and
continue communication.
 The device that calls this method must support Wi-Fi direct.
 The method creates a p2p group with the current device as its group owner.
 In addition to hosting an access point, it also allows other Wi-Fi direct enabled
devices to connect with it in regular fashion.
 Connecting with a Wi-Fi programmatically (if SSID and password are known):
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 39
Wi-Fi direct demo
Plus code walkthrough for our use case
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 40
Agenda
 Network interfaces.
 Basic socket communication.
 Network service discovery.
 Wi-Fi direct.
 Wi-Fi direct service discovery.
 Bluetooth low energy (BLE).
 Demos (wherever needed)
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 41
Discover devices and services in vicinity
(Irrespective of device connection status)
Wi-Fi direct service
discovery
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 42
Wi-Fi direct service discovery
 Similar function as NSD.
 Similar code like Wi-Fi direct.
 Kind of like a combination of both. And also more complex than BOTH.
 Same classes and listeners are used as in Wi-Fi direct.
 Here we find services in nearby devices. (Can work for devices in the
same network too).
 In this WifiP2pManager’s addLocalService() method is used.
 There is an additional option for adding key value pairs in a map (100-
200 bytes). This map can be received with service discovery.
 Any small additional data can be shared with service (like device’s port it
is listening to, name, device info etc.)
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 43
Wi-Fi direct adding local service
WifiP2pManager’s addLocalService():
WifiP2pServiceInfo is a class for storing service information that is advertised over a Wi-
Fi peer-to-peer setup. It has two direct subclasses. Both are bonjour service info:
 WifiP2pDnsSdServiceInfo – domain name system service discovery (service info)
 WifiP2pUpnpServiceInfo – Universal plug and play (service info)
For our use case we will be using the former in place of WifiP2pServiceInfo. With DNS-
SD service info we have an option to advertise additional data (relatively small 100-200
bytes). For this use case we will advertise port information.
Once the port and IP information is determined, rest of the work is similar (socket
programming).
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 44
Setting WifiP2pDnsSdServiceInfo
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 45
Wi-Fi direct service discovery
request
WifiP2pManager’s addServiceRequest():
Since we are searching for DNS-SD service the WifiP2pServiceRequest will be
of NDS-SD type.
Setting service discovery response listeners to WifiP2pManager
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 46
Wi-Fi direct service response
listeners
WifiP2pManager.DnsSdServiceResponseListener interface has only one
method:
WifiP2pManager.DnsSdTxtRecordListener interface:
Other callbacks and broadcasts are same as Wi-Fi direct
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 47
Wi-Fi direct… rest of it and more
 Rest of the flow in Wi-Fi Direct service discovery is same as Wi-Fi direct.
 A device will call connect.
 Other device will receive an invitation to connect.
 There will be role negotiation based on GO intent parameter.
 A group will be formed with one group owner and others as clients.
 After that information can be exchanged.
 If we look at our use case the only difference is instead of pre-fixing a
port, we are adding the port information when adding service request.
So no listeners on pre-fixed port.
 All the services should be unregistered and discovery request must be
stopped when exiting an application. We don’t want to drain the battery
for no reason.
 Use createGroup() method discussed in Wi-Fi direct section only when
supporting legacy devices.
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 48
Wi-Fi direct service
discovery demo
And a glance at some of the important
methods and classes in demo code
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 49
Agenda
 Network interfaces.
 Basic socket communication.
 Network service discovery.
 Wi-Fi direct.
 Wi-Fi direct service discovery.
 Bluetooth low energy (BLE).
 Demos (wherever needed)
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 50
In Android
Bluetooth Low Energy
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 51
In Android, BLE stack was introduced
in API 18 Jelly Bean 4.3, in July 2013.
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 52
Scene
Peripheral
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 53
Scene
Peripheral
Central
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 54
Generic Access Profile Roles
Broadcaster Observer
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 55
Generic Access Profile Roles
Peripheral
aka Slave
Central
aka Master
connect
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 56
GATT Server-Client
Server
(holding data)
Client
(asking data)
transact
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 57
Services
Characteristics
Class {
}
attributes;
get();
set();
• Read
• Write
Characteristics
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 58
BluetoothManager manager =
(BluetoothManager) context
.getSystemService(
Context.BLUETOOTH_SERVICE);
mBluetoothAdapter =
manager.getAdapter();
<uses-feature
android:name="android.hardware.bluetooth_le"
android:required="true"
/>
mBluetoothLeScanner
.startScan(callback);
mBluetoothLeScanner =
mBluetoothAdapter.getBluetoothLeScanner();
<uses-permission
android:name=
"android.permission.BLUETOOTH_ADMIN" />
ScanCallback{
public void onScanResult(int
callbackType, ScanResult result) {
}
public void onScanFailed(int
errorCode) {
}
}
mBluetoothGatt =
mBluetoothDevice.connectGatt(
context,
autoConnect,
gattCallback) ;
mBluetoothDevice =
bleScanResult.getBluetoothDevice();
BluetoothGattCallback {
public void
onConnectionStateChange(
BluetoothGatt gatt,
int status,
int newState) ;
}
if( newState ==
BluetoothProfile.STATE_CONNECTED)
bluetoothGatt.discoverServices();
BluetoothGattCallback {
public void onServicesDiscovered(
BluetoothGatt gatt, int status);
}
List<BluetoothGattService> serviceList =
gatt.getServices();
bluetoothGattCharacteristic.setValue(
intToByteArray(color));
List<BluetoothGattCharacteristic> list =
bluetoothGattService.getCharacteristics();
bluetoothGatt.writeCharacteristic(
bluetoothGattCharacteristic)
BluetoothGattCallback {
public void onCharacteristicWrite(
BluetoothGatt gatt,
BluetoothGattCharacteristic
characteristic,
int status) ;
}
if( status ==
BluetoothGatt.GATT_SUCCESS)
Video removed…
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 67
Demo code available at…
• https://github.com/drulabs/LocalDash
• https://github.com/navalkishoreb/IoT/tree/zone_dis
covery/Android
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 68
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 69
References
• https://docs.oracle.com/javase/tutorial/networking/nifs/index.html
• https://docs.oracle.com/javase/7/docs/api/java/net/NetworkInterface.html
• http://www.tldp.org/LDP/nag2/x-087-2-hwconfig.tour.html
• http://adbshell.com/commands/adb-shell-netstat
• https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterface
Names/
• https://docs.oracle.com/javase/tutorial/networking/sockets/definition.html
• https://developer.android.com/guide/topics/connectivity/wifip2p.html
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 70
BLE has 40 channels of 2Mhz bandwidth
Out of which 37 are Data channels
Only 3 are for Advertising data
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 71
GND
+5Volt
+3.3 Volt
_Tx_
_Rx_
PIN 6

Weitere ähnliche Inhalte

Was ist angesagt?

An Introduction To Android
An Introduction To AndroidAn Introduction To Android
An Introduction To Android
GoogleTecTalks
 
Data Capture in IBM WebSphere Premises Server - Aldo Eisma, IBM
Data Capture in IBM WebSphere Premises Server - Aldo Eisma, IBMData Capture in IBM WebSphere Premises Server - Aldo Eisma, IBM
Data Capture in IBM WebSphere Premises Server - Aldo Eisma, IBM
mfrancis
 
Android unveiled (I)
Android unveiled (I)Android unveiled (I)
Android unveiled (I)
denian00
 
Ch1 hello, android
Ch1 hello, androidCh1 hello, android
Ch1 hello, android
Jehad2012
 
Manish Chasta - Securing Android Applications
Manish Chasta - Securing Android ApplicationsManish Chasta - Securing Android Applications
Manish Chasta - Securing Android Applications
Positive Hack Days
 

Was ist angesagt? (20)

Android for Java Developers
Android for Java DevelopersAndroid for Java Developers
Android for Java Developers
 
An Introduction To Android
An Introduction To AndroidAn Introduction To Android
An Introduction To Android
 
Open Android
Open AndroidOpen Android
Open Android
 
Android for Java Developers at OSCON 2010
Android for Java Developers at OSCON 2010Android for Java Developers at OSCON 2010
Android for Java Developers at OSCON 2010
 
Data Capture in IBM WebSphere Premises Server - Aldo Eisma, IBM
Data Capture in IBM WebSphere Premises Server - Aldo Eisma, IBMData Capture in IBM WebSphere Premises Server - Aldo Eisma, IBM
Data Capture in IBM WebSphere Premises Server - Aldo Eisma, IBM
 
Android For Managers Slides
Android For Managers SlidesAndroid For Managers Slides
Android For Managers Slides
 
Fm3610071011
Fm3610071011Fm3610071011
Fm3610071011
 
Android os
Android osAndroid os
Android os
 
Marakana Android Internals
Marakana Android InternalsMarakana Android Internals
Marakana Android Internals
 
503 434-438
503 434-438503 434-438
503 434-438
 
Introduction to android basics
Introduction to android basicsIntroduction to android basics
Introduction to android basics
 
Android By Vipin
Android By VipinAndroid By Vipin
Android By Vipin
 
Android Architecture
Android ArchitectureAndroid Architecture
Android Architecture
 
Android unveiled (I)
Android unveiled (I)Android unveiled (I)
Android unveiled (I)
 
Campus portal for wireless devices
Campus portal for wireless devicesCampus portal for wireless devices
Campus portal for wireless devices
 
Ch1 hello, android
Ch1 hello, androidCh1 hello, android
Ch1 hello, android
 
Manish Chasta - Securing Android Applications
Manish Chasta - Securing Android ApplicationsManish Chasta - Securing Android Applications
Manish Chasta - Securing Android Applications
 
Android 1
Android 1 Android 1
Android 1
 
Android 1
Android 1 Android 1
Android 1
 
Eclipse Edje Project Status
Eclipse Edje Project StatusEclipse Edje Project Status
Eclipse Edje Project Status
 

Andere mochten auch

SAP Presentation
SAP PresentationSAP Presentation
SAP Presentation
SANGONeT
 
Patrice Slupowski ( Orange ) - New Media as a challenge on 4+ screens
Patrice Slupowski ( Orange ) - New Media as a challenge on 4+ screensPatrice Slupowski ( Orange ) - New Media as a challenge on 4+ screens
Patrice Slupowski ( Orange ) - New Media as a challenge on 4+ screens
ronewmedia_academy
 
Greycroft - Why Accountants Don’t Run Startups
Greycroft - Why Accountants Don’t Run StartupsGreycroft - Why Accountants Don’t Run Startups
Greycroft - Why Accountants Don’t Run Startups
Stanford University
 

Andere mochten auch (20)

Offering For Tech Companies
Offering For Tech CompaniesOffering For Tech Companies
Offering For Tech Companies
 
Software development in a startup
Software development in a startupSoftware development in a startup
Software development in a startup
 
Lean Software Startup: Customer Development (lecture)
Lean Software Startup: Customer Development (lecture)Lean Software Startup: Customer Development (lecture)
Lean Software Startup: Customer Development (lecture)
 
SAP Presentation
SAP PresentationSAP Presentation
SAP Presentation
 
Emprende con éxito en Internet de José Villalobos
Emprende con éxito en Internet de José Villalobos Emprende con éxito en Internet de José Villalobos
Emprende con éxito en Internet de José Villalobos
 
Lean Startup for Non-startups
Lean Startup for Non-startupsLean Startup for Non-startups
Lean Startup for Non-startups
 
Startup safary athens 2014 oleg lola
Startup safary athens 2014 oleg lolaStartup safary athens 2014 oleg lola
Startup safary athens 2014 oleg lola
 
Technology Challenges in Building New Media Applications
Technology Challenges in Building New Media ApplicationsTechnology Challenges in Building New Media Applications
Technology Challenges in Building New Media Applications
 
Microservices: Redundancy = Maintainability! (Eberhard Wolff Technology Stream)
Microservices: Redundancy = Maintainability! (Eberhard Wolff Technology Stream)Microservices: Redundancy = Maintainability! (Eberhard Wolff Technology Stream)
Microservices: Redundancy = Maintainability! (Eberhard Wolff Technology Stream)
 
Legacy modernization
Legacy modernizationLegacy modernization
Legacy modernization
 
Big Data – Are You Ready?
Big Data – Are You Ready?Big Data – Are You Ready?
Big Data – Are You Ready?
 
Patrice Slupowski ( Orange ) - New Media as a challenge on 4+ screens
Patrice Slupowski ( Orange ) - New Media as a challenge on 4+ screensPatrice Slupowski ( Orange ) - New Media as a challenge on 4+ screens
Patrice Slupowski ( Orange ) - New Media as a challenge on 4+ screens
 
The Minimum Lovable Product - UX Brighton January 2015
The Minimum Lovable Product - UX Brighton January 2015The Minimum Lovable Product - UX Brighton January 2015
The Minimum Lovable Product - UX Brighton January 2015
 
SiliconAlley Startup Services for Investors
SiliconAlley Startup Services for InvestorsSiliconAlley Startup Services for Investors
SiliconAlley Startup Services for Investors
 
Using OKRs in Startups with Nabeel Hyatt
Using OKRs in Startups with Nabeel HyattUsing OKRs in Startups with Nabeel Hyatt
Using OKRs in Startups with Nabeel Hyatt
 
Why is my MVP a POC (ProductCamp Vancouver 2015)
Why is my MVP a POC (ProductCamp Vancouver 2015)Why is my MVP a POC (ProductCamp Vancouver 2015)
Why is my MVP a POC (ProductCamp Vancouver 2015)
 
The Evolution of Offshoring
The Evolution of OffshoringThe Evolution of Offshoring
The Evolution of Offshoring
 
Building Your Digital Dream Team - Guide for PR Professionals
Building Your Digital Dream Team - Guide for PR ProfessionalsBuilding Your Digital Dream Team - Guide for PR Professionals
Building Your Digital Dream Team - Guide for PR Professionals
 
Greycroft - Why Accountants Don’t Run Startups
Greycroft - Why Accountants Don’t Run StartupsGreycroft - Why Accountants Don’t Run Startups
Greycroft - Why Accountants Don’t Run Startups
 
Lean product development for startups
Lean product development for startupsLean product development for startups
Lean product development for startups
 

Ähnlich wie Connected World in android - Local data sharing and service discovery

Web Server(Apache),
Web Server(Apache), Web Server(Apache),
Web Server(Apache),
webhostingguy
 
Web Server(Apache),
Web Server(Apache), Web Server(Apache),
Web Server(Apache),
webhostingguy
 
Internet of 'Hidden' Things: How to Build a Confidential IOT Network using TO...
Internet of 'Hidden' Things: How to Build a Confidential IOT Network using TO...Internet of 'Hidden' Things: How to Build a Confidential IOT Network using TO...
Internet of 'Hidden' Things: How to Build a Confidential IOT Network using TO...
Abhinav Biswas
 

Ähnlich wie Connected World in android - Local data sharing and service discovery (20)

JavaOne 2016 - Faces Counter
JavaOne 2016 -  Faces CounterJavaOne 2016 -  Faces Counter
JavaOne 2016 - Faces Counter
 
Web Server(Apache),
Web Server(Apache), Web Server(Apache),
Web Server(Apache),
 
Web Server(Apache),
Web Server(Apache), Web Server(Apache),
Web Server(Apache),
 
The Datacenter Network You Wish You Had: It's yours for the taking.
The Datacenter Network You Wish You Had: It's yours for the taking.The Datacenter Network You Wish You Had: It's yours for the taking.
The Datacenter Network You Wish You Had: It's yours for the taking.
 
The Datacenter Network You Wish You Had
The Datacenter Network You Wish You HadThe Datacenter Network You Wish You Had
The Datacenter Network You Wish You Had
 
IoT projects in Eclipse Foundation using LwM2M (IoT World 2017 Workshop)
IoT projects in Eclipse Foundation using LwM2M (IoT World 2017 Workshop)IoT projects in Eclipse Foundation using LwM2M (IoT World 2017 Workshop)
IoT projects in Eclipse Foundation using LwM2M (IoT World 2017 Workshop)
 
Internet of Things Security & Privacy
Internet of Things Security & PrivacyInternet of Things Security & Privacy
Internet of Things Security & Privacy
 
Cisco Connect Vancouver 2017 - Cisco's Digital Network Architecture - deeper ...
Cisco Connect Vancouver 2017 - Cisco's Digital Network Architecture - deeper ...Cisco Connect Vancouver 2017 - Cisco's Digital Network Architecture - deeper ...
Cisco Connect Vancouver 2017 - Cisco's Digital Network Architecture - deeper ...
 
Financial Grade OAuth & OpenID Connect
Financial Grade OAuth & OpenID ConnectFinancial Grade OAuth & OpenID Connect
Financial Grade OAuth & OpenID Connect
 
Internet of 'Hidden' Things: How to Build a Confidential IOT Network using TO...
Internet of 'Hidden' Things: How to Build a Confidential IOT Network using TO...Internet of 'Hidden' Things: How to Build a Confidential IOT Network using TO...
Internet of 'Hidden' Things: How to Build a Confidential IOT Network using TO...
 
3 Software Stacks for IoT Solutions
3 Software Stacks for IoT Solutions3 Software Stacks for IoT Solutions
3 Software Stacks for IoT Solutions
 
IOT Networks
IOT NetworksIOT Networks
IOT Networks
 
Advance Java Programming( CM5I) 4. Networking Basics
Advance Java Programming( CM5I) 4. Networking BasicsAdvance Java Programming( CM5I) 4. Networking Basics
Advance Java Programming( CM5I) 4. Networking Basics
 
Demystifying Software Defined Networking (SDN)
Demystifying Software Defined Networking (SDN)Demystifying Software Defined Networking (SDN)
Demystifying Software Defined Networking (SDN)
 
Demystifying Software Defined Networking (SDN)
Demystifying Software Defined Networking (SDN)Demystifying Software Defined Networking (SDN)
Demystifying Software Defined Networking (SDN)
 
Decoding the IoT Ecosystem
Decoding the IoT EcosystemDecoding the IoT Ecosystem
Decoding the IoT Ecosystem
 
Cloud Computing and the Promise of Everything as a Service
Cloud Computing and the Promise of Everything as a ServiceCloud Computing and the Promise of Everything as a Service
Cloud Computing and the Promise of Everything as a Service
 
Node summit workshop
Node summit workshopNode summit workshop
Node summit workshop
 
Running your Spring Apps in the Cloud Javaone 2014
Running your Spring Apps in the Cloud Javaone 2014Running your Spring Apps in the Cloud Javaone 2014
Running your Spring Apps in the Cloud Javaone 2014
 
AT&T Shape Hackathon Kick-off
AT&T Shape Hackathon Kick-offAT&T Shape Hackathon Kick-off
AT&T Shape Hackathon Kick-off
 

Mehr von Talentica Software

Android Media Player Development
Android Media Player DevelopmentAndroid Media Player Development
Android Media Player Development
Talentica Software
 

Mehr von Talentica Software (18)

Typescript: Beginner to Advanced
Typescript: Beginner to AdvancedTypescript: Beginner to Advanced
Typescript: Beginner to Advanced
 
Web 3.0
Web 3.0Web 3.0
Web 3.0
 
Remix
RemixRemix
Remix
 
Web Performance & Latest in React
Web Performance & Latest in ReactWeb Performance & Latest in React
Web Performance & Latest in React
 
Nodejs Chapter 3 - Design Pattern
Nodejs Chapter 3 - Design PatternNodejs Chapter 3 - Design Pattern
Nodejs Chapter 3 - Design Pattern
 
Node js Chapter-2
Node js Chapter-2Node js Chapter-2
Node js Chapter-2
 
Node.js Chapter1
Node.js Chapter1Node.js Chapter1
Node.js Chapter1
 
Micro Frontends
Micro FrontendsMicro Frontends
Micro Frontends
 
Test Policy and Practices
Test Policy and PracticesTest Policy and Practices
Test Policy and Practices
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Setting Up Development Environment For Google App Engine & Python | Talentica
Setting Up Development Environment For Google App Engine & Python | TalenticaSetting Up Development Environment For Google App Engine & Python | Talentica
Setting Up Development Environment For Google App Engine & Python | Talentica
 
Mobile App Monetization - Ecosystem & Emerging Trends
Mobile App Monetization - Ecosystem & Emerging TrendsMobile App Monetization - Ecosystem & Emerging Trends
Mobile App Monetization - Ecosystem & Emerging Trends
 
Android Media Player Development
Android Media Player DevelopmentAndroid Media Player Development
Android Media Player Development
 
Cross Platform Mobile Technologies
Cross Platform Mobile TechnologiesCross Platform Mobile Technologies
Cross Platform Mobile Technologies
 
Big Data Technologies - Hadoop
Big Data Technologies - HadoopBig Data Technologies - Hadoop
Big Data Technologies - Hadoop
 
Continous Integration: A Case Study
Continous Integration: A Case StudyContinous Integration: A Case Study
Continous Integration: A Case Study
 
Flex on Grails - Rich Internet Applications With Rapid Application Development
Flex on Grails - Rich Internet Applications With Rapid Application DevelopmentFlex on Grails - Rich Internet Applications With Rapid Application Development
Flex on Grails - Rich Internet Applications With Rapid Application Development
 
Building scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thriftBuilding scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thrift
 

Kürzlich hochgeladen

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 

Kürzlich hochgeladen (20)

Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 

Connected World in android - Local data sharing and service discovery

  • 1. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. Connected world in android Local data sharing and service discovery Presented by: Kaushal Dhruw Naval Barthwal
  • 2. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 2 About PMD • Started in August 2013 • “Increase awareness of fast growing mobile technology among Developers” • Currently has 3000+ members • 21 meetups so far
  • 3. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 3 Team • Ashutosh • Tarun • Arvind • Kaushal • Suyash • Vijendra • Talentica Mobile Community
  • 4. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 4 Agenda  Network interfaces.  Basic socket communication.  Network service discovery.  Wi-Fi direct.  Wi-Fi direct service discovery.  Bluetooth low energy (BLE).  Demos (wherever needed)
  • 5. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 5 Introduction Network interfaces
  • 6. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 6 Network interface  A Network interface is a point of interconnection between a device and a public or private network.  It can be a hardware (Network interface card).  Or can be implemented in software.  Some network interfaces:  wlan: wireless networking interface.  lo: loopback interface (localhost, usually 127.0.0.1).  rmnet: usually associated with mobile data and USB tethering.  p2p: a peer-to-peer interface.  eth, en: Ethernet card interface.  dummy: alternative for loopback interfaces. NetworkInterface.getNetworkInterfaces() //gets list of all available network interfaces
  • 7. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 7 Network interface methods  isUp(): Whether the network interface is up and running.  isVirtual(): Whether the network interface is virtual or sub- interface.  getSubInterfaces(): gets all the sub interfaces bound to this network interface (like eth0:1 for eth0)  supportsMulticast(): checks multicast support.  getInetAddresses(): get all the addresses bound to this network interface.  getHardwareAddress(): usually MAC.  getByName():  getByInetAddress():  getByIndex():
  • 8. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 8 Network interface selection  When a socket is created it automatically determines which network (that is currently up and running) to use.  Most of the times you will not have to worry about the network interface.  When you want to use the address of a particular network interface, use the get methods discussed in previous slide.  To listen to all the network interfaces, bind your socket to “0.0.0.0”  Loopback and dummy interfaces are used for localhost connection testing.  use adb shell ifconfig to list all available network interfaces.
  • 9. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 9 Agenda  Network interfaces.  Basic socket communication.  Network service discovery.  Wi-Fi direct.  Wi-Fi direct service discovery.  Bluetooth low energy (BLE).  Demos (wherever needed)
  • 10. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 10 Generic java not specific to android Basic socket communication
  • 11. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 11 Basic socket communication  A socket is basically an end point for two-way communication link between two devices.  In a typical client-server architecture.  Server runs on a specific computer and has a socket that is bound to a specific port, the server listens for a client to make connection request in that socket.  Client knows the host name of server and port it is listening on. The client system usually assigns a port to rendezvous with server’s machine and port.  Client receives confirmation of connection acceptance and can use the socket for communicating with server.  Listening on a port for client requests is done via ServerSocket. A ServerSocket class provides a system independent implementation of the server side of client/server socket connection. ServerSocket serverSocket = new ServerSocket(port); Socket s = serverSocket.accept();
  • 12. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 12 Basic socket communication contd…
  • 13. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 13 Steps involved in socket communication  Create a ServerSocket. This socket waits for a connection from a client on a specified port and blocks until it happens, so do this in a background thread.  Create a client Socket. The client uses the IP address and port of the server socket to connect to the server device.  Send data from the client to the server. When the client socket successfully connects to the server socket, you can send data from the client to the server with byte streams.  The server socket waits for a client connection (with the accept() method). This call blocks until a client connects, so call this in another thread. When a connection happens, the server device can receive the data from the client.  And carry out any actions with this data, such as saving it to a file or presenting it to the user.
  • 14. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 14 Client/server sockets ServerSocket mServer = new ServerSocket(mPort); While(true){ Socket s = mServer.accept(); //process s and streams and return response if required } socket = new Socket(host, port); OutputStream outputStream = socket.getOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(outputStream); oos.writeObject(transferObject); oos.close(); Server Client mPort = (new ServerSocket(0)).getLocalPort()
  • 15. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 15 Use case we are solving (Local chat) Share files & Send chat & Receive chat and file from other devices Share files & Send chat & Receive chat and file from other devices Device 1 Device 2
  • 16. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 16 Agenda  Network interfaces.  Basic socket communication.  Network service discovery.  Wi-Fi direct.  Wi-Fi direct service discovery.  Bluetooth low energy (BLE).  Demos (wherever needed)
  • 17. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 17 Discover services and devices in the same network Network service discovery (NSD)
  • 18. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 18 Network service discover (NSD)  android.net.nsd.* package is used.  It helps with many use cases like file sharing, multi-player games etc.  Android network service discovery allows your app to identify other devices in the same network that support the services your app requests.  NSD allows us to register our service(s) on the network, discover it, and connect with it.  Important classes:  NsdManager  NsdServiceInfo  Although internet is not used, INTERNET permission is required for socket communication.
  • 19. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 19 Basic steps in NSD
  • 20. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 20 NSD Service registration Creating NsdServiceInfo Object
  • 21. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 21 NSD Service registration Listener
  • 22. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 22 NSD Service discovery
  • 23. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 23 NSD Service discovery Listener
  • 24. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 24 Resolving discovered NSD service • NsdManager.ResolveListener Note**: Do not forget to stop discovery and unregister service when app closes
  • 25. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 25 NSD Demo plus code walkthrough
  • 26. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 26 Agenda  Network interfaces.  Basic socket communication.  Network service discovery.  Wi-Fi direct.  Wi-Fi direct service discovery.  Bluetooth low energy (BLE).  Demos (wherever needed)
  • 27. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 27 Connect with devices in vicinity (Wi-Fi p2p in android) Wi-Fi direct
  • 28. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 28 Wi-Fi direct  Wi-Fi direct is a Wi-Fi certified standard enabling devices to connect with each other without requiring a wireless access point.  Using this devices can communicate with each other at typical Wi-Fi speeds, unlike ad-hoc wireless connections (which allows two or more devices to connect and communicate, and has a limit of 11Mbps).  And Wi-Fi direct has much simpler setup that ad-hoc network.  Wi-Fi direct assigns each member a limited access point (if it is Wi-Fi direct enabled).  Wi-Fi direct uses WPS and WPA2 to prevent unauthorized access and keep communications private.
  • 29. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 29 Wi-Fi direct contd…  Wi-Fi direct allows devices to connect to each other and form groups. Not only one-to-one, but also one-to-many.  Compatible devices negotiate their roles in the connection:  One of these assumes role of a traditional access point. Called Group Owner (GO).  Other devices including non-Wi-Fi direct devices connect to the Group owner or Access point as P2P clients.  Any P2P device can assume the role of a Group owner and P2P client. The purpose of role negotiation is to determine which of the peer devices will exchange group characteristics (like operating channel, WPS configuration, is the group persistent etc.).  Devices can communicate their willingness to become group owner with the GO intent attribute (0-15).  After the role negotiation a confirmation is sent and devices move to their specified roles. GO starts operating in Access point mode.
  • 30. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 30 Wi-Fi direct and android  Android’s Wi-Fi P2P framework complies with the Wi-Fi direct certification program. It allows devices running android 4.0+ (API 14+) with appropriate hardware to connect easily without an intermediate access point.  Android Wi-Fi P2P API consists of:  Methods that allows us to discover, request and connect to peers (android.net.wifi.p2p.WifiP2pManager).  Listeners that notifies us of success and failure of WifiP2pmanager’s method calls.  Intents to notify specific events, such as new peer joined, connection dropped etc. (like WIFI_P2P_PEERS_CHANGED_ACTION and WIFI_P2P_CONNECTION_CHANGED_ACTION)  A single call to WifiP2pManager’s discover peers is enough for Wi-Fi direct peer discovery. Connection however with Wi-Fi direct group requires user’s consent. This is unlike NSD.
  • 31. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 31 Wi-Fi direct – Permissions
  • 32. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 32 Wi-Fi direct – starting peer discovery
  • 33. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 33 Wi-Fi direct – getting peer list This broadcast receiver needs to be registered dynamically. It notifies when peer list has changed so peer list can be requested from WifiP2pManager
  • 34. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 34 Wi-Fi direct – getting peer list contd… When WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION is received in the broadcast receiver, peer list can be requested. With WifiP2pManager.requestPeers() method.
  • 35. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 35 Wi-Fi direct – WifiP2pDevice Important method in WifiP2pDeviceList is getDeviceList() which gives a collection of WifiP2pDevice, it has the following important fields
  • 36. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 36 Wi-Fi direct – Connecting to a peer Once a peer is discovered, connection request can be sent
  • 37. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 37 Connecting to a peer – WifiP2pInfo Once connection is successful a connection info request can be issued via WifiP2pManager. Which send callback to WifiP2pManager.ConnectionInfoListener. It has only one method described below: WifiP2pInfo 
  • 38. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 38 WifiP2pManager - createGroup  This method is to support older devices that do not support Wi-Fi direct. It creates an Access point which non-Wi-Fi direct can connect to (like a regular Wi-Fi), and continue communication.  The device that calls this method must support Wi-Fi direct.  The method creates a p2p group with the current device as its group owner.  In addition to hosting an access point, it also allows other Wi-Fi direct enabled devices to connect with it in regular fashion.  Connecting with a Wi-Fi programmatically (if SSID and password are known):
  • 39. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 39 Wi-Fi direct demo Plus code walkthrough for our use case
  • 40. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 40 Agenda  Network interfaces.  Basic socket communication.  Network service discovery.  Wi-Fi direct.  Wi-Fi direct service discovery.  Bluetooth low energy (BLE).  Demos (wherever needed)
  • 41. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 41 Discover devices and services in vicinity (Irrespective of device connection status) Wi-Fi direct service discovery
  • 42. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 42 Wi-Fi direct service discovery  Similar function as NSD.  Similar code like Wi-Fi direct.  Kind of like a combination of both. And also more complex than BOTH.  Same classes and listeners are used as in Wi-Fi direct.  Here we find services in nearby devices. (Can work for devices in the same network too).  In this WifiP2pManager’s addLocalService() method is used.  There is an additional option for adding key value pairs in a map (100- 200 bytes). This map can be received with service discovery.  Any small additional data can be shared with service (like device’s port it is listening to, name, device info etc.)
  • 43. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 43 Wi-Fi direct adding local service WifiP2pManager’s addLocalService(): WifiP2pServiceInfo is a class for storing service information that is advertised over a Wi- Fi peer-to-peer setup. It has two direct subclasses. Both are bonjour service info:  WifiP2pDnsSdServiceInfo – domain name system service discovery (service info)  WifiP2pUpnpServiceInfo – Universal plug and play (service info) For our use case we will be using the former in place of WifiP2pServiceInfo. With DNS- SD service info we have an option to advertise additional data (relatively small 100-200 bytes). For this use case we will advertise port information. Once the port and IP information is determined, rest of the work is similar (socket programming).
  • 44. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 44 Setting WifiP2pDnsSdServiceInfo
  • 45. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 45 Wi-Fi direct service discovery request WifiP2pManager’s addServiceRequest(): Since we are searching for DNS-SD service the WifiP2pServiceRequest will be of NDS-SD type. Setting service discovery response listeners to WifiP2pManager
  • 46. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 46 Wi-Fi direct service response listeners WifiP2pManager.DnsSdServiceResponseListener interface has only one method: WifiP2pManager.DnsSdTxtRecordListener interface: Other callbacks and broadcasts are same as Wi-Fi direct
  • 47. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 47 Wi-Fi direct… rest of it and more  Rest of the flow in Wi-Fi Direct service discovery is same as Wi-Fi direct.  A device will call connect.  Other device will receive an invitation to connect.  There will be role negotiation based on GO intent parameter.  A group will be formed with one group owner and others as clients.  After that information can be exchanged.  If we look at our use case the only difference is instead of pre-fixing a port, we are adding the port information when adding service request. So no listeners on pre-fixed port.  All the services should be unregistered and discovery request must be stopped when exiting an application. We don’t want to drain the battery for no reason.  Use createGroup() method discussed in Wi-Fi direct section only when supporting legacy devices.
  • 48. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 48 Wi-Fi direct service discovery demo And a glance at some of the important methods and classes in demo code
  • 49. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 49 Agenda  Network interfaces.  Basic socket communication.  Network service discovery.  Wi-Fi direct.  Wi-Fi direct service discovery.  Bluetooth low energy (BLE).  Demos (wherever needed)
  • 50. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 50 In Android Bluetooth Low Energy
  • 51. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 51 In Android, BLE stack was introduced in API 18 Jelly Bean 4.3, in July 2013.
  • 52. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 52 Scene Peripheral
  • 53. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 53 Scene Peripheral Central
  • 54. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 54 Generic Access Profile Roles Broadcaster Observer
  • 55. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 55 Generic Access Profile Roles Peripheral aka Slave Central aka Master connect
  • 56. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 56 GATT Server-Client Server (holding data) Client (asking data) transact
  • 57. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 57 Services Characteristics Class { } attributes; get(); set(); • Read • Write Characteristics
  • 58. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 58 BluetoothManager manager = (BluetoothManager) context .getSystemService( Context.BLUETOOTH_SERVICE); mBluetoothAdapter = manager.getAdapter(); <uses-feature android:name="android.hardware.bluetooth_le" android:required="true" />
  • 60. ScanCallback{ public void onScanResult(int callbackType, ScanResult result) { } public void onScanFailed(int errorCode) { } }
  • 62. BluetoothGattCallback { public void onConnectionStateChange( BluetoothGatt gatt, int status, int newState) ; } if( newState == BluetoothProfile.STATE_CONNECTED)
  • 63. bluetoothGatt.discoverServices(); BluetoothGattCallback { public void onServicesDiscovered( BluetoothGatt gatt, int status); } List<BluetoothGattService> serviceList = gatt.getServices();
  • 65. BluetoothGattCallback { public void onCharacteristicWrite( BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) ; } if( status == BluetoothGatt.GATT_SUCCESS)
  • 67. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 67 Demo code available at… • https://github.com/drulabs/LocalDash • https://github.com/navalkishoreb/IoT/tree/zone_dis covery/Android
  • 68. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 68
  • 69. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 69 References • https://docs.oracle.com/javase/tutorial/networking/nifs/index.html • https://docs.oracle.com/javase/7/docs/api/java/net/NetworkInterface.html • http://www.tldp.org/LDP/nag2/x-087-2-hwconfig.tour.html • http://adbshell.com/commands/adb-shell-netstat • https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterface Names/ • https://docs.oracle.com/javase/tutorial/networking/sockets/definition.html • https://developer.android.com/guide/topics/connectivity/wifip2p.html
  • 70. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 70 BLE has 40 channels of 2Mhz bandwidth Out of which 37 are Data channels Only 3 are for Advertising data
  • 71. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 71 GND +5Volt +3.3 Volt _Tx_ _Rx_ PIN 6

Hinweis der Redaktion

  1. Intro, welcome and other PMD things
  2. Why it is important to know about network interfaces? Show ifconfig adb command And java program
  3. Show ifconfig adb command And java program
  4. Question about port sharing between android devices. Why port number should not be prefixed?
  5. Define service
  6. serviceInfo.getPort() will not give the port info unless resolved Service type = “_<protocol>._<transportlayer>” International Assigned Numbers Authority (IANA)  http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xml
  7. Explain error code = 2 (Wi-Fi is not on or not connected) Wi-Fi is either off or not connected
  8. Single service discovery method with discovery listener call back
  9. Now after the services are discovered, either show it in UI or resolve it to get entire service information
  10. We will discuss important methods of WifiP2pManager in coming slides
  11. Take a look at WifiP2pDeviceList, WifiP2pDevice & WifiP2pManager
  12. There you go, a list of peer’s is available
  13. This sends a connection request to the peer device. Invitation request to peer device. User has to manually accept the request.
  14. From here onwards we can continue our socket communication.
  15. This is important because it can connect to both Wi-Fi direct and non-Wi-Fi direct legacy devices (those connect to Group owner as regular access point) The network name starts with “Direct-xy”
  16. This is used in nearby device discovery such as printers and other smart devices. This has a wide variety of applications. Right from xbox controllers to wireless printers to IOT systems
  17. WifiP2pServiceInfo is a class for storing service information that is advertised over a Wi-Fi peer-to-peer setup. Universal Plug and Play (UPnP) is a set of networking protocols that permits networked devices, such as personal computers, printers, Internet gateways, Wi-Fi access points and mobile devices to seamlessly discover each other's presence on the network and establish functional network services for data sharing, communications, and entertainment.  UPnP is intended primarily for residential networks without enterprise-class devices
  18. Before we dig deeper into Android. Few things we need to understand about BLE protocol stack
  19. Android introduced BLE stack in Jelly Bean 4.3 <pause> API level 18 <pause><enter> Though became stable and reliable from Android Lollipop 5.0 <pause> API level 21 <enter> Next we will look into<pause> certain API calls and steps <pause>that android framework specifies<pause> to work with BLE devices.<enter> http://www.electronicsweekly.com/blogs/eyes-on-android/what-is/what-is-bluedroid-2014-01/ BlueDroid was introduced in 4.2 http://www.argenox.com/blog/android-5-0-lollipop-brings-ble-improvements/ The story of Android’s Bluetooth support is long. Android originally used the open source BlueZ stack that is common in Linux. But Google removed the bluez stack that was originally in Android because of its GPL license. Instead it decided to develop its own BlueDroid Bluetooth stack with Broadcom. BlueZ is GPL BlueDroid Apache License Improved Scanning Scanning, and in particular background scanning, was a big problem in Android for two reasons. The first is that scanning drains a battery tremendously. BLE scanning in Android was stopping the device from going into standby mode and would quickly drain batteries. The normal reaction of users was to disable Bluetooth to save on battery life, but this caused the phone to lose connection with BLE devices. The end result was that communicating with BLE enabled devices and getting data would take much longer, frustrating users. With Android L, the scanning process has been offloaded to lower layers which allows the smartphone to go to sleep. Users don’t have to disable Bluetooth when not using it actively. Support for BLE Peripheral and Broadcaster Modes Till 4.4 android framework supported only central mode.
  20. Device will scan for near by peripheral to connect
  21. Device will scan for near by peripheral to connect Central will initiate connection Peripheral will respond to accept
  22. A device could be a broadcaster or an observer.
  23. A device could be a broadcaster or an observer.
  24. Server is hosting services . Each service can have one or more characteristics And Each characteristic could read and written. Analogy is similar to a Class its attributes which can be get or set
  25. get BluetoothManager<enter> from application context using getSystemService method. To ensure your application has proper device compatibility <enter>. Declare ble hardware feature requirement in manifest file<pause><enter> Grab BluetoothAdapter from the manager object.<enter> The purpose of a <uses-feature> declaration is to inform any external entity of the set of hardware and software features on which your application depends. The element offers a requiredattribute that lets you specify whether your application requires and cannot function without the declared feature, or whether it prefers to have the feature but can function without it. BluetoothManager High level manager used to obtain an instance of an BluetoothAdapter and to conduct overall Bluetooth Management. The BluetoothAdapter is required for any and all Bluetooth activity. luetoothManager what does it manages?? BluetoothAdapter purpose??
  26. get BluetoothLeScanner<enter> from BluetoothAdapter<pause> BluetoothLeScanner<pause> provides methods<pause> to perform scan related operations <pause>for Bluetooth LE devices Now execute startScan<enter> method It will run asynchronously Provide a callback object to receive scan results.. To perform device discovery get hold of bluetooth admin permission Note: <pause>To enable device discovery <enter> get hold of Bluetooth_Admin permission<enter> If you want your app to initiate device discovery or manipulate Bluetooth settings, you must also declare theBLUETOOTH_ADMIN permission. Note: If you use the BLUETOOTH_ADMIN permission, then you must also have theBLUETOOTH permission. Allows applications to discover and pair bluetooth devices. callbackType Determines how this callback was triggered. Could be one of * {@link ScanSettings#CALLBACK_TYPE_ALL_MATCHES}, * {@link ScanSettings#CALLBACK_TYPE_FIRST_MATCH} or * {@link ScanSettings#CALLBACK_TYPE_MATCH_LOST} Bluetooth_admin what doors does this permission opens?? What do we need this particular permission
  27. After a successful device discovery You will receive ScanResult <enter> in your ScanCallback implementation.<pause> ScanResult <enter> contains ble device information ScanResult Device BluetoothDevice: Remote bluetooth device that is found. scanRecord ScanRecord: Scan record including both advertising data and scan response data. Rssi int: Received signal strength. timestampNanos long: Device timestamp when the scan result was observed. http://www.metageek.com/training/resources/understanding-rssi.html callbackType Determines how this callback was triggered. Could be one of * {@link ScanSettings#CALLBACK_TYPE_ALL_MATCHES}, * {@link ScanSettings#CALLBACK_TYPE_FIRST_MATCH} o * {@link ScanSettings#CALLBACK_TYPE_MATCH_LOST}??? How rssi calculates?? ScanResult contains what?? And what errorCode could be produced?? When you have multiple ble devices you will feed your list adapter with scan result and add on the basis of uuid
  28. get bluetooth device <enter> from scan result. We will connect to the ble device, which is at this moment is acting as a GATT server. <enter> connectGatt method returns BluetoothGatt object.<pause> mBluetoothGatt is used to conduct GATT <loud>client operations. To automatically connect as soon as the remote device becomes available pass autoConnect true<pause> GattCallback will receive connection related responses.<pause> optional while waiting for callback Show intermediate progress bar. Optional It could be understood as mysql driver connection object is used to communicate mysql database server. BluetoothGatt functionality to enable communication with Bluetooth Smart or Smart Ready devices. /** * Connect to GATT Server hosted by this device. Caller acts as GATT client. * The callback is used to deliver results to Caller, such as connection status as well * as any further GATT client operations. * The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct * GATT client operations. * @param callback GATT callback handler that will receive asynchronous callbacks. * @param autoConnect Whether to directly connect to the remote device (false) * or to automatically connect as soon as the remote * device becomes available (true). * @throws IllegalArgumentException if callback is null */
  29. Whatever happens to connection is communicated <enter> through onConnectionStateChange callback Check if it was connected <enter> successfully Gatt is the connection object Status is like 200ok where operation was successfull newState tells our current connection state /** * Callback indicating when GATT client has connected/disconnected to/from a remote * GATT server. * * @param gatt GATT client * @param status Status of the connect or disconnect operation. * {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds. * @param newState Returns the new connection state. Can be one of * {@link BluetoothProfile#STATE_DISCONNECTED} or * {@link BluetoothProfile#STATE_CONNECTED} */ Note this would be called in separate thread
  30. Once we are connected successfully to GATT server , we will <enter> discover services. When service discovery is completed <enter> onServicesDiscovered is called in GattCallback implementation Retrieve services <enter> and obtain desired service using particular UUID<enter> Once service discovery is completed, * the {@link BluetoothGattCallback#onServicesDiscovered} callback is * triggered. /** * Callback indicating when GATT client has connected/disconnected to/from a remote * GATT server. * * @param gatt GATT client * @param status Status of the connect or disconnect operation. * {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds. * @param newState Returns the new connection state. Can be one of * {@link BluetoothProfile#STATE_DISCONNECTED} or * {@link BluetoothProfile#STATE_CONNECTED} */ Note this would be called in separate thread What is ble service?? Example??
  31. A particular service may hold multiple characteristics<enter><pause> Retrieve desired characteristic using UUID. Now set color value<enter> by moving seekbar on application. And write <enter> this characteristic onto server. /** * Callback indicating when GATT client has connected/disconnected to/from a remote * GATT server. * * @param gatt GATT client * @param status Status of the connect or disconnect operation. * {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds. * @param newState Returns the new connection state. Can be one of * {@link BluetoothProfile#STATE_DISCONNECTED} or * {@link BluetoothProfile#STATE_CONNECTED} */ Note this would be called in separate thread
  32. We will receive A callback<enter> onCharacteristicWrite And <enter> if write is Successful <enter> we will see Led strip changed its color /** * Callback indicating the result of a characteristic write operation. * * <p>If this callback is invoked while a reliable write transaction is * in progress, the value of the characteristic represents the value * reported by the remote device. An application should compare this * value to the desired value to be written. If the values don't match, * the application must abort the reliable write transaction. * * @param gatt GATT client invoked {@link BluetoothGatt#writeCharacteristic} * @param characteristic Characteristic that was written to the associated * remote device. * @param status The result of the write operation * {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds. */
  33. Now we will make few <loud>connections step by step<pause><enter> Take arduino uno<enter> Take breadboard<enter> Take Led strip<enter> Now connect 5Volt output from arduino to led strip power supply pin<enter> Connect ground pin from arduino to breadboard<enter> Connect Pin 6 from arduino to led strip Data input pin<enter> Take HM-10 Module , connect the ground wire with breadboad <enter> Now connect 3.3Volt output from arduino to power pin supply of HM -10<enter> Connect Pin 10 the Receiving end of arduino <enter> to Transmitting end of HM-10 <enter> Connect Pin 11 the Transmitting end of arduino to Receiving pin of HM -10