Está en la página 1de 13

Africa Information

Technology Initiative

J2ME Mini-Lecture: Bluetooth

AITI 2009
Bluetooth
•  enables communications for devices
physically located close to one another
•  radio connectivity technology designed to
create Personal Area Networks ( PAN )
–  printing a file to a printer nearby
–  finding out more info on a dream home for
sale
–  seeing if the girl across the room is single and
available for dinner
2
Africa Information Technology Initiative © 2009 http://aiti.mit.edu
Network
•  one master device and seven slave
devices
•  master device can also act as slave device
-> creates a bridge to expand network

Java API for Bluetooth Wireless Technology


  also known as JSR 82
javax.bluetooth

3
Africa Information Technology Initiative © 2009 http://aiti.mit.edu
Bluetooth protocol stack

4
Africa Information Technology Initiative © 2009 http://aiti.mit.edu
Bluetooth implementation
•  contains both hardware and software
components
•  software enables data to be interchanged
between locally connected devices
•  Different interactions
–  Discovery: find other devices, possible usefulness
–  Client Activities: printing to nearby printer
–  Server Activities: provide services/information
–  Peer Activities: exchanging info back and fourth

5
Africa Information Technology Initiative © 2009 http://aiti.mit.edu
Bluetooth API
•  Accessing Local Bluetooth Stack
LocalDevice class -> get info from stack

public String getBluetoothAddress();


- returns address for the device

public DeviceClass getDeviceClass();


- returns major class of device

6
Africa Information Technology Initiative © 2009 http://aiti.mit.edu
more methods
DiscoveryAgent getDiscoveryAgent();
- used to obtain instance of device's DiscoveryAgent

String getFriendlyName();
- returns name of your device

To determine whether device is discoverable by


others: int getDiscoverable();
Make device discoverable:
boolean setDiscoverable(int mode)

7
Africa Information Technology Initiative © 2009 http://aiti.mit.edu
Making LocalDevice instance
•  static LocalDevice getLocalDevice();
–  called a Bluetooth Manager

LocalDevice myDevice = LocalDevice.getLocalDevice();

Getting properties of Bluetooth software stack

static String getProperty(String property);

pg. 200, table 12-1 for list of properties

8
Africa Information Technology Initiative © 2009 http://aiti.mit.edu
Discovering Devices
•  DiscoveryAgent
–  helps discover devices/services in PAN
–  request status of agent
–  tell agent to call you back when it discovers
DiscoveryAgent myDa =
LocalDevice.getInstance().getDiscoveryA
gent();

 now we can use myDa to start and stop discovery of devices

9
Africa Information Technology Initiative © 2009 http://aiti.mit.edu
Discovery methods
•  To start discovering:
boolean startInquiry(int accessCode,
DiscoveryListener listener);
–  access codes determines type of access
•  usually DiscoveryAgent.GIAC
–  each device that is discovered, registered listener will
receive notification

must implement the DiscoveryListener interface

10
Africa Information Technology Initiative © 2009 http://aiti.mit.edu
DiscoveryListener interface
•  void deviceDiscovered(RemoteDevice btDevice,
DeviceClass cod);
–  method is called when device is discovered
•  void inquiryCompleted(int discType);
–  method is called when inquiry process is completed
–  discType possibilities:
•  DiscoveryListener.INQUIRY_COMPLETED
•  DiscoveryListener.INQUIRY_TERMINATED
•  DiscoveryListener.INQUIRY_ERROR

public boolean cancelInquiry(DiscoveryListener


listener); //stop discovery on same registered listener

11
Africa Information Technology Initiative © 2009 http://aiti.mit.edu
Discovering Services
•  with RemoteDevice,you can search through services

public int searchServices(int[] attrSet,


UUID[] uuidSet, RemoteDevice btDev,
DiscoveryListener discListener)

–  btDev specifies the RemoteDevice


–  uuidSet contains one UUID for each service
–  discListener is called with results and transaction
ID
–  attrSet contains service record attributes
12
Africa Information Technology Initiative © 2009 http://aiti.mit.edu
resources

http://java.sun.com/javame/reference/apis/
jsr082/

Bluetooth API

13
Africa Information Technology Initiative © 2009 http://aiti.mit.edu

También podría gustarte