SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Bluetooth Hacking
     Stefano Sanna - JUG Sardegna
    Emanuele Di Saverio - JUG Roma




                      Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma
                                              Javaday IV – Roma – 01/30/2010
Outline

• Who we are
• The relevance of Bluetooth on mobile devices
• Android & Bluetooth: an unconsummated marriage
• Happy hacking!
• Bluetooth API for Android 1.x
• Official API for Android 2.x
• Demo: Android controls Arduino Bluetooth
                             Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma
                                              Javaday IV – Roma – 30 gennaio 2010
Who we are

• Stefano Sanna
 • Senior Solution Engineer Android @ beeweeb SpA
 • Author of the book “Java Micro Edition”, Hoepli (2007)
 • Main designer Bluetooth API for Android 1.x

• Emanuele Di Saverio
 • Scrum Master and Senior Developer @ beeweeb SpA
 • SCMAD, SCJP
 • Committer easy-bluetooth spin-off for Android

                                  Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma
                                                   Javaday IV – Roma – 30 gennaio 2010
Bluetooth on Android

• early Android
  • Wrapper Java su Bluez
• Android 0.9
  • API Bluetooth disappears!

• Android 1.x
  • No API for developers
• Android 2.x
  • Exposes an API allowing discovery of remote devices,
   opening and accepting RFCOMM connections
                                  Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma
                                                   Javaday IV – Roma – 30 gennaio 2010
The relevance of Bluetooth

• Without a dedicated API is not possible to:
  • Discovery devices and services
  • Transfer files with Bluetooth FTP and OBEX

  • GPS connections, gamepads, medical devices

  • Remote control of embedded modules and sensor networks

  • Robotic application (i.e. LEGO Mindstorms)
                                  Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma
                                                   Javaday IV – Roma – 30 gennaio 2010
A lot of devices out there...




  Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma
                    Javaday IV – Roma – 30 gennaio 2010
Happy
Hacking!


     Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma
                             Javaday IV – Roma – 01/30/2010
System service & Reflection

• Bluetooth Service is accessible like every other
   Android Service:

Object bluetoothService = context.getSystemService(“bluetooth”);


   Having the right Class, we can leverage la reflection
   to know (and invoke!) the methods:

Class bluetoothServiceClass = bluetoothService.class;

Method[] bluetoothMethods = bluetoothServiceClass.getMethods();

                                      Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma
                                                       Javaday IV – Roma – 30 gennaio 2010
Available Methods
public android.bluetooth.BluetoothDevice(android.bluetooth.IBluetoothDevice)
public boolean android.bluetooth.BluetoothDevice.cancelBondProcess(java.lang.String)
public void android.bluetooth.BluetoothDevice.cancelDiscovery()
public boolean android.bluetooth.BluetoothDevice.cancelPin(java.lang.String)
public boolean android.bluetooth.BluetoothDevice.createBond(java.lang.String)
public boolean android.bluetooth.BluetoothDevice.disable()
public boolean android.bluetooth.BluetoothDevice.disconnectRemoteDeviceAcl(java.lang.String)
public boolean android.bluetooth.BluetoothDevice.enable()
public java.lang.String android.bluetooth.BluetoothDevice.getAddress()
public int android.bluetooth.BluetoothDevice.getBluetoothState()
public int android.bluetooth.BluetoothDevice.getBondState(java.lang.String)
public java.lang.String android.bluetooth.BluetoothDevice.getCompany()
public int android.bluetooth.BluetoothDevice.getDiscoverableTimeout()
public java.lang.String android.bluetooth.BluetoothDevice.getManufacturer()
public java.lang.String android.bluetooth.BluetoothDevice.getName()
public int android.bluetooth.BluetoothDevice.getRemoteClass(java.lang.String)
public java.lang.String android.bluetooth.BluetoothDevice.getRemoteCompany(java.lang.String)
public [B android.bluetooth.BluetoothDevice.getRemoteFeatures(java.lang.String)
public java.lang.String android.bluetooth.BluetoothDevice.getRemoteManufacturer(java.lang.String)
public java.lang.String android.bluetooth.BluetoothDevice.getRemoteName(java.lang.String)
public java.lang.String android.bluetooth.BluetoothDevice.getRemoteRevision(java.lang.String)
public boolean
android.bluetooth.BluetoothDevice.getRemoteServiceChannel(java.lang.String,short,android.bluetoot
h.IBluetoothDeviceCallback)

                                                     Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma
                                                                       Javaday IV – Roma – 30 gennaio 2010
Available Methods
public android.bluetooth.BluetoothDevice(android.bluetooth.IBluetoothDevice)
public boolean android.bluetooth.BluetoothDevice.cancelBondProcess(java.lang.String)
public void android.bluetooth.BluetoothDevice.cancelDiscovery()




                          O X!
public boolean android.bluetooth.BluetoothDevice.cancelPin(java.lang.String)
public boolean android.bluetooth.BluetoothDevice.createBond(java.lang.String)




                        O E
public boolean android.bluetooth.BluetoothDevice.disable()
public boolean android.bluetooth.BluetoothDevice.disconnectRemoteDeviceAcl(java.lang.String)




                       T L
public boolean android.bluetooth.BluetoothDevice.enable()
public java.lang.String android.bluetooth.BluetoothDevice.getAddress()
public int android.bluetooth.BluetoothDevice.getBluetoothState()
public int android.bluetooth.BluetoothDevice.getBondState(java.lang.String)




                          P
public java.lang.String android.bluetooth.BluetoothDevice.getCompany()
public int android.bluetooth.BluetoothDevice.getDiscoverableTimeout()




                        M
public java.lang.String android.bluetooth.BluetoothDevice.getManufacturer()
public java.lang.String android.bluetooth.BluetoothDevice.getName()




                      O
public int android.bluetooth.BluetoothDevice.getRemoteClass(java.lang.String)
public java.lang.String android.bluetooth.BluetoothDevice.getRemoteCompany(java.lang.String)
public [B android.bluetooth.BluetoothDevice.getRemoteFeatures(java.lang.String)




                     C
public java.lang.String android.bluetooth.BluetoothDevice.getRemoteManufacturer(java.lang.String)
public java.lang.String android.bluetooth.BluetoothDevice.getRemoteName(java.lang.String)
public java.lang.String android.bluetooth.BluetoothDevice.getRemoteRevision(java.lang.String)
public boolean
android.bluetooth.BluetoothDevice.getRemoteServiceChannel(java.lang.String,short,android.bluetoot
h.IBluetoothDeviceCallback)

                                                     Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma
                                                                       Javaday IV – Roma – 30 gennaio 2010
Permission

• First Step: to access Bluetooth functionalities we
   need to declare two Permissions in the Manifest:


<uses-permission android:name="android.permission.BLUETOOTH" />

<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />




                                      Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma
                                                       Javaday IV – Roma – 30 gennaio 2010
Remote device discovery

LocalBluetoothDevice local = LocalBluetoothDevice.init(context);

local.setListener(new LocalBluetoothDeviceListener() {

      public void scanStarted() {
         // scan has started...
      }

      public void scanCompleted(ArrayList<String> devices) {
         // scan is over
      }
});

local.scan();     // start scan...




                                        Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma
                                                          Javaday IV – Roma – 30 gennaio 2010
Open an RFCOMM socket from client

RemoteBluetoothDevice dev = local.getRemoteBluetoothDevice(address);

dev.setListener(new RemoteBluetoothDeviceListener() {

   public void paired() {
     // we open sockets and I/O streams...         3
     BluetoothSocket socket = dev.openSocket(1);
     InputStream input = socket.getInputStream();
     OutputStream output = socket.getOutputStream();
   }

   public void pinRequested() {
      // show dialog for PIN input                                   2
   }
});

dev.pair();   1
                                      Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma
                                                        Javaday IV – Roma – 30 gennaio 2010
Compatible devices

• HTC Dream
• HTC Magic
• HTC Tattoo
• Samsung Galaxy i7500
• Samsung Galaxy i5700
• Huawei U8220
• Sony-Ericsson XPERIA X10
                             Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma
                                              Javaday IV – Roma – 30 gennaio 2010
Bluetooth API for Android 1.x

• The only opensource library (Apache 2.0) for
    accessing Bluetooth stack on Android 1.x
•   Features:
    • turn on/off Bluetooth
    • discovery of remote devices and RFCOMM bound to a
        service
    •   opening of RFCOMM connections from client
• Works without the necessity of root access
• Check it out!
    • http://code.google.com/p/android-bluetooth
                                    Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma
                                                     Javaday IV – Roma – 30 gennaio 2010
Bluetooth API for Android 1.x

• More than 1000 downloads!
• Used in commercial and free projects:
  • Inspired Bluetooth File Transfer by Medieval Software, the
      most succesful file transfer application on the Android
      Market
  •   Used in Amarino (developed by MIT), first framework for
      controlling Arduino via an Android device
  •   Used in GoPayment by Intuit Inc., for credit card payment
      via swiper and Bluetooth printer
  •   Used in DUBwise project, for flying helicpoters :)
                                    Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma
                                                     Javaday IV – Roma – 30 gennaio 2010
Main limitations

• It’s not possible to register an SDP (Service
  Discovery Protocol) service on the database, even
  though is possible to create RFCOMM server socket

• If a device inquiry is issue just after phone startup,
  the native call interferes with a system scan process
  and Bluetooth stack become unusable

• Compatibility problems with HTC Hero

                                 Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma
                                                  Javaday IV – Roma – 30 gennaio 2010
Permission on socket dbus




  Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma
                    Javaday IV – Roma – 30 gennaio 2010
Android 2.x API

• Android 2.0 : Bluetooth officially in the SDK!
• Yay! But...
  • No direct control over pairing
  • No direct access to RFCOMM channels
  • No service discovery
    ...not so :
• Android style: based on Intents and Receivers
  • Publish/Subscribe paradigm, a little clunky!
                                    Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma
                                                     Javaday IV – Roma – 30 gennaio 2010
Discovery in Android 2.x


BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();

IntentFilter filter = new IntentFilter();

filter.addAction(BluetoothDevice.ACTION_FOUND);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);

//also can register for DISCOVERY_STARTED Action

context.registerReceiver(receiver, filter);

adapter.startDiscovery();




                                      Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma
                                                        Javaday IV – Roma – 30 gennaio 2010
BroadcastReceiver
private final BroadcastReceiver receiver = new BroadcastReceiver() {

 public void onReceive(Context ctx, Intent intent) {

         final String action = intent.getAction();

             if (action.equals(BluetoothDevice.ACTION_FOUND)) {
                    BluetoothDevice device = (BluetoothDevice)
                 intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

                //process device
             } else if
             (action.equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED))
             {
                //done :o)
             }
     }
};

                                          Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma
                                                            Javaday IV – Roma – 30 gennaio 2010
Socket e stream I/O

//given a valid “BluetoothDevice”...

UUID uuidOfTargetService =
UUID.nameUUIDFromBytes(“2d26618601fb47c28d9f10b8ec891363”);

BluetoothSocket socket =
rbd.createRfcommSocketToServiceRecord(uuidOfTargetService);

socket.connect();

InputStream input = socket.getInputStream();
OutputStream output = socket.getOutputStream();

....

socket.close();


                                       Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma
                                                         Javaday IV – Roma – 30 gennaio 2010
Android good practices

• It’s important to keep in mind good practices of
 Android (and Java) programming!:

  • I/O operations always in a separate Thread

  • update UI via Handler

  • unregister Receivers before destroying Context


                                  Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma
                                                   Javaday IV – Roma – 30 gennaio 2010
Is a separate library still useful?

• In spite of Android 2.0 API, a Bluetooth library would
 be greatly useful!

  • Access to hidden features (via reflection)
  • Expose a simpler API
  • 1.x vs 2.x abstraction   Retrocompatibility!

• ....working out Easy Bluetooth
  • Check it out:
   http://android-bluetooth.googlecode.com/svn/
                                 Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma
                                                  Javaday IV – Roma – 30 gennaio 2010
Android controls Arduino

• We want to use Android to control
 via Bluetooth a LED and read
 a temperature




                              Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma
                                               Javaday IV – Roma – 30 gennaio 2010
Arduino

• “Arduino is an open-source electronics prototyping
    platform based on flexible, easy-to-use hardware and
    software. [...] It can sense the environment by
    receiving input from a variety of sensors and can
    affect its surroundings by controlling lights, motors,
    and other actuators.
•   Strictly MADE IN ITALY!

• http://www.arduino.cc

                                 Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma
                                                  Javaday IV – Roma – 30 gennaio 2010
Arduino Source
int LED_PIN = 13;    int LM35_PIN = 2;

void setup() {                                   Hardware:
  Serial.begin(115200);

}
  pinMode(LED_PIN, OUTPUT);
                                                 • Arduino Bluetooth
                                                 • Prototype shield e breadboard
void loop() {                                    • LM35 Temperature Sensor
  if (Serial.available() > 0) {
    int inByte = Serial.read();

    switch (inByte) {
       case '1':
         digitalWrite(LED_PIN, HIGH);
         Serial.write('1');
         break;
       case '0':                         void readTemp() {
         digitalWrite(LED_PIN, LOW);       int temp = analogRead(LM35_PIN);
         Serial.write('0');                temp= ( 5.0 * temp * 100.0) / 1024.0;
         break;                            Serial.write(temp);
       case 'r':
                                         }
         readTemp();
         break;
    }
}

                                           Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma
                                                             Javaday IV – Roma – 30 gennaio 2010
Android Source


// define commands...
byte LED_ON_REQUEST = ‘1’;
byte LED_OFF_REQUEST = ‘0’;
byte READ_TEMPERATURE = ‘r’;

[...]

// in the Thread we send comandi and read responses...
output.write(request);
final int response = input.read();

if (request == 'r') {
   handler.post(new Runnable() {
      public void run() {
         String temp = Integer.toString(response);
         Toast.makeText(Controller.this, "LM35 Sensor: " + temp + "°C", 4000).show();

        });
}


                                                     Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma
                                                                       Javaday IV – Roma – 30 gennaio 2010
DEMO!

                                   Starring:

Motorola Milestone (Android 2.0), HTC Magic (Android 1.6) and Arduino Bluetooth



                                           Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma
                                                                   Javaday IV – Roma – 01/30/2010
Resources

• Android
  • http://developer.android.com
  • http://source.android.com

• Bluetooth API for Android 1.x e Easy Bluetooth
  • http://code.google.com/p/android-bluetooth

• Arduino
  • http://www.arduino.cc

                                   Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma
                                                    Javaday IV – Roma – 30 gennaio 2010
References

• Stefano Sanna
 • gerdavax AT gmail DOT com
 • http://www.gerdavax.it

• Emanuele Di Saverio
 • emanuele DOT disaverio AT gmail DOT com




                               Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma
                                                Javaday IV – Roma – 30 gennaio 2010
THANK YOU!

Stefano & Emanuele & i rispettivi JUG!




                       Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma
                                               Javaday IV – Roma – 01/30/2010

Weitere ähnliche Inhalte

Was ist angesagt?

Laporan multi client
Laporan multi clientLaporan multi client
Laporan multi clientichsanbarokah
 
Concurrecy techdrop
Concurrecy techdropConcurrecy techdrop
Concurrecy techdropMichael Barker
 
Java осень 2012 лекция 2
Java осень 2012 лекция 2Java осень 2012 лекция 2
Java осень 2012 лекция 2Technopark
 
A Layered Architecture for the Model-driven Development of Distributed Simula...
A Layered Architecture for the Model-driven Development of Distributed Simula...A Layered Architecture for the Model-driven Development of Distributed Simula...
A Layered Architecture for the Model-driven Development of Distributed Simula...Daniele Gianni
 
Advanced Sockets Programming
Advanced Sockets ProgrammingAdvanced Sockets Programming
Advanced Sockets Programmingelliando dias
 
分散式系統
分散式系統分散式系統
分散式系統acksinkwung
 
Network Sockets
Network SocketsNetwork Sockets
Network SocketsPeter R. Egli
 
There's more than web
There's more than webThere's more than web
There's more than webMatt Evans
 
Socket Programming
Socket  ProgrammingSocket  Programming
Socket Programmingleminhvuong
 
Creating an Arduino Web Server from scratch hardware and software
Creating an Arduino Web Server from scratch hardware and softwareCreating an Arduino Web Server from scratch hardware and software
Creating an Arduino Web Server from scratch hardware and softwareJustin Mclean
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programmingelliando dias
 
Non blocking io with netty
Non blocking io with nettyNon blocking io with netty
Non blocking io with nettyZauber
 

Was ist angesagt? (20)

Ppt of socket
Ppt of socketPpt of socket
Ppt of socket
 
Laporan multi client
Laporan multi clientLaporan multi client
Laporan multi client
 
Sockets intro
Sockets introSockets intro
Sockets intro
 
Concurrecy techdrop
Concurrecy techdropConcurrecy techdrop
Concurrecy techdrop
 
Mattbrenner
MattbrennerMattbrenner
Mattbrenner
 
Socket System Calls
Socket System CallsSocket System Calls
Socket System Calls
 
Java NIO.2
Java NIO.2Java NIO.2
Java NIO.2
 
Java осень 2012 лекция 2
Java осень 2012 лекция 2Java осень 2012 лекция 2
Java осень 2012 лекция 2
 
A Layered Architecture for the Model-driven Development of Distributed Simula...
A Layered Architecture for the Model-driven Development of Distributed Simula...A Layered Architecture for the Model-driven Development of Distributed Simula...
A Layered Architecture for the Model-driven Development of Distributed Simula...
 
Advanced Sockets Programming
Advanced Sockets ProgrammingAdvanced Sockets Programming
Advanced Sockets Programming
 
分散式系統
分散式系統分散式系統
分散式系統
 
Npc14
Npc14Npc14
Npc14
 
Network Sockets
Network SocketsNetwork Sockets
Network Sockets
 
Lecture10
Lecture10Lecture10
Lecture10
 
There's more than web
There's more than webThere's more than web
There's more than web
 
Socket Programming
Socket  ProgrammingSocket  Programming
Socket Programming
 
Creating an Arduino Web Server from scratch hardware and software
Creating an Arduino Web Server from scratch hardware and softwareCreating an Arduino Web Server from scratch hardware and software
Creating an Arduino Web Server from scratch hardware and software
 
Sockets
SocketsSockets
Sockets
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 
Non blocking io with netty
Non blocking io with nettyNon blocking io with netty
Non blocking io with netty
 

Andere mochten auch

Android & Bluetooth: hacking e applicazioni
Android & Bluetooth: hacking e applicazioniAndroid & Bluetooth: hacking e applicazioni
Android & Bluetooth: hacking e applicazioniStefano Sanna
 
Bca 2nd sem-u-3-basic computer programming and micro programmed control
Bca 2nd sem-u-3-basic computer programming and micro programmed controlBca 2nd sem-u-3-basic computer programming and micro programmed control
Bca 2nd sem-u-3-basic computer programming and micro programmed controlRai University
 
theday, windows hacking with commandline
theday, windows hacking with commandlinetheday, windows hacking with commandline
theday, windows hacking with commandlineidsecconf
 
Central processing unit
Central processing unitCentral processing unit
Central processing unitKamal Acharya
 
Multiprocessor
MultiprocessorMultiprocessor
MultiprocessorKamal Acharya
 
Micro Programmed Control Unit
Micro Programmed Control UnitMicro Programmed Control Unit
Micro Programmed Control UnitKamal Acharya
 
Input Output Organization
Input Output OrganizationInput Output Organization
Input Output OrganizationKamal Acharya
 
08. Central Processing Unit (CPU)
08. Central Processing Unit (CPU)08. Central Processing Unit (CPU)
08. Central Processing Unit (CPU)Akhila Dakshina
 

Andere mochten auch (10)

Android & Bluetooth: hacking e applicazioni
Android & Bluetooth: hacking e applicazioniAndroid & Bluetooth: hacking e applicazioni
Android & Bluetooth: hacking e applicazioni
 
Bca 2nd sem-u-3-basic computer programming and micro programmed control
Bca 2nd sem-u-3-basic computer programming and micro programmed controlBca 2nd sem-u-3-basic computer programming and micro programmed control
Bca 2nd sem-u-3-basic computer programming and micro programmed control
 
Lecture 22
Lecture 22Lecture 22
Lecture 22
 
theday, windows hacking with commandline
theday, windows hacking with commandlinetheday, windows hacking with commandline
theday, windows hacking with commandline
 
Bluetooth Hacking
Bluetooth HackingBluetooth Hacking
Bluetooth Hacking
 
Central processing unit
Central processing unitCentral processing unit
Central processing unit
 
Multiprocessor
MultiprocessorMultiprocessor
Multiprocessor
 
Micro Programmed Control Unit
Micro Programmed Control UnitMicro Programmed Control Unit
Micro Programmed Control Unit
 
Input Output Organization
Input Output OrganizationInput Output Organization
Input Output Organization
 
08. Central Processing Unit (CPU)
08. Central Processing Unit (CPU)08. Central Processing Unit (CPU)
08. Central Processing Unit (CPU)
 

Ähnlich wie Android Bluetooth Hacking Java Day2010 Eng

Rococo Software Overview Q3 2010
Rococo Software Overview Q3 2010Rococo Software Overview Q3 2010
Rococo Software Overview Q3 2010Sean O'Sullivan
 
Rococo Software Q3 2010
Rococo Software Q3 2010Rococo Software Q3 2010
Rococo Software Q3 2010Sean O'Sullivan
 
JSR-82 Bluetooth tutorial
JSR-82 Bluetooth tutorialJSR-82 Bluetooth tutorial
JSR-82 Bluetooth tutorialSoham Sengupta
 
ARTIFICIAL INTELLIGENCE DESKTOP VOICE ASSISTANT IN PYTHON
ARTIFICIAL INTELLIGENCE DESKTOP VOICE ASSISTANT IN PYTHONARTIFICIAL INTELLIGENCE DESKTOP VOICE ASSISTANT IN PYTHON
ARTIFICIAL INTELLIGENCE DESKTOP VOICE ASSISTANT IN PYTHONIRJET Journal
 
The Physical World meets the Web
The Physical World meets the WebThe Physical World meets the Web
The Physical World meets the WebMaximiliano Firtman
 
Android Framework
Android FrameworkAndroid Framework
Android FrameworkCodeAndroid
 
IRJET- IOT Dune Buggy –Control it from Anywhere
IRJET- IOT Dune Buggy –Control it from AnywhereIRJET- IOT Dune Buggy –Control it from Anywhere
IRJET- IOT Dune Buggy –Control it from AnywhereIRJET Journal
 
IRJET- IOT Dune Buggy –Control it from Anywhere
IRJET-  	  IOT Dune Buggy –Control it from AnywhereIRJET-  	  IOT Dune Buggy –Control it from Anywhere
IRJET- IOT Dune Buggy –Control it from AnywhereIRJET Journal
 
MikroTik Hotspot 2.0 (IEEE 802.11u) - MUM Jakarta 2016
MikroTik Hotspot 2.0 (IEEE 802.11u) - MUM Jakarta 2016MikroTik Hotspot 2.0 (IEEE 802.11u) - MUM Jakarta 2016
MikroTik Hotspot 2.0 (IEEE 802.11u) - MUM Jakarta 2016Rofiq Fauzi
 
Introduction to Home Automation
Introduction to Home AutomationIntroduction to Home Automation
Introduction to Home AutomationRuslan Ulanov
 
Enterprise Developer Journey to the IoT
Enterprise Developer Journey to the IoTEnterprise Developer Journey to the IoT
Enterprise Developer Journey to the IoTBurr Sutter
 
Global Azure Bootcamp 2017 - Azure IoT Hub with LoRa Connectivity
Global Azure Bootcamp 2017 - Azure IoT Hub with LoRa ConnectivityGlobal Azure Bootcamp 2017 - Azure IoT Hub with LoRa Connectivity
Global Azure Bootcamp 2017 - Azure IoT Hub with LoRa ConnectivityAndri Yadi
 
Exploring the physical web
Exploring the physical webExploring the physical web
Exploring the physical webyiibu
 
Gnome, linux mobile stacks, and you
Gnome, linux mobile stacks, and youGnome, linux mobile stacks, and you
Gnome, linux mobile stacks, and youAndrew Savory
 
Ice cream-sandwich
Ice cream-sandwichIce cream-sandwich
Ice cream-sandwichNaughattyy Poem
 
Estimote beacons and simple Android application (full)
Estimote beacons and simple Android application (full)Estimote beacons and simple Android application (full)
Estimote beacons and simple Android application (full)davidepiccardi
 
Google Developer DAy 2010 Japan: HTML5 についての最新情報 (マイク スミス)
Google Developer DAy 2010 Japan: HTML5 についての最新情報 (マイク スミス)Google Developer DAy 2010 Japan: HTML5 についての最新情報 (マイク スミス)
Google Developer DAy 2010 Japan: HTML5 についての最新情報 (マイク スミス)Google Developer Relations Team
 
Controlpcviabluetoothenablemobile 091028150632-phpapp01
Controlpcviabluetoothenablemobile 091028150632-phpapp01Controlpcviabluetoothenablemobile 091028150632-phpapp01
Controlpcviabluetoothenablemobile 091028150632-phpapp01nagapriyanka
 
Control Pc Via Bluetooth Enable Mobile
Control Pc Via Bluetooth Enable MobileControl Pc Via Bluetooth Enable Mobile
Control Pc Via Bluetooth Enable MobileSamiul Hoque
 
Controlpcviabluetoothenablemobile 091028150632-phpapp01
Controlpcviabluetoothenablemobile 091028150632-phpapp01Controlpcviabluetoothenablemobile 091028150632-phpapp01
Controlpcviabluetoothenablemobile 091028150632-phpapp01ramaswamireddy challa
 

Ähnlich wie Android Bluetooth Hacking Java Day2010 Eng (20)

Rococo Software Overview Q3 2010
Rococo Software Overview Q3 2010Rococo Software Overview Q3 2010
Rococo Software Overview Q3 2010
 
Rococo Software Q3 2010
Rococo Software Q3 2010Rococo Software Q3 2010
Rococo Software Q3 2010
 
JSR-82 Bluetooth tutorial
JSR-82 Bluetooth tutorialJSR-82 Bluetooth tutorial
JSR-82 Bluetooth tutorial
 
ARTIFICIAL INTELLIGENCE DESKTOP VOICE ASSISTANT IN PYTHON
ARTIFICIAL INTELLIGENCE DESKTOP VOICE ASSISTANT IN PYTHONARTIFICIAL INTELLIGENCE DESKTOP VOICE ASSISTANT IN PYTHON
ARTIFICIAL INTELLIGENCE DESKTOP VOICE ASSISTANT IN PYTHON
 
The Physical World meets the Web
The Physical World meets the WebThe Physical World meets the Web
The Physical World meets the Web
 
Android Framework
Android FrameworkAndroid Framework
Android Framework
 
IRJET- IOT Dune Buggy –Control it from Anywhere
IRJET- IOT Dune Buggy –Control it from AnywhereIRJET- IOT Dune Buggy –Control it from Anywhere
IRJET- IOT Dune Buggy –Control it from Anywhere
 
IRJET- IOT Dune Buggy –Control it from Anywhere
IRJET-  	  IOT Dune Buggy –Control it from AnywhereIRJET-  	  IOT Dune Buggy –Control it from Anywhere
IRJET- IOT Dune Buggy –Control it from Anywhere
 
MikroTik Hotspot 2.0 (IEEE 802.11u) - MUM Jakarta 2016
MikroTik Hotspot 2.0 (IEEE 802.11u) - MUM Jakarta 2016MikroTik Hotspot 2.0 (IEEE 802.11u) - MUM Jakarta 2016
MikroTik Hotspot 2.0 (IEEE 802.11u) - MUM Jakarta 2016
 
Introduction to Home Automation
Introduction to Home AutomationIntroduction to Home Automation
Introduction to Home Automation
 
Enterprise Developer Journey to the IoT
Enterprise Developer Journey to the IoTEnterprise Developer Journey to the IoT
Enterprise Developer Journey to the IoT
 
Global Azure Bootcamp 2017 - Azure IoT Hub with LoRa Connectivity
Global Azure Bootcamp 2017 - Azure IoT Hub with LoRa ConnectivityGlobal Azure Bootcamp 2017 - Azure IoT Hub with LoRa Connectivity
Global Azure Bootcamp 2017 - Azure IoT Hub with LoRa Connectivity
 
Exploring the physical web
Exploring the physical webExploring the physical web
Exploring the physical web
 
Gnome, linux mobile stacks, and you
Gnome, linux mobile stacks, and youGnome, linux mobile stacks, and you
Gnome, linux mobile stacks, and you
 
Ice cream-sandwich
Ice cream-sandwichIce cream-sandwich
Ice cream-sandwich
 
Estimote beacons and simple Android application (full)
Estimote beacons and simple Android application (full)Estimote beacons and simple Android application (full)
Estimote beacons and simple Android application (full)
 
Google Developer DAy 2010 Japan: HTML5 についての最新情報 (マイク スミス)
Google Developer DAy 2010 Japan: HTML5 についての最新情報 (マイク スミス)Google Developer DAy 2010 Japan: HTML5 についての最新情報 (マイク スミス)
Google Developer DAy 2010 Japan: HTML5 についての最新情報 (マイク スミス)
 
Controlpcviabluetoothenablemobile 091028150632-phpapp01
Controlpcviabluetoothenablemobile 091028150632-phpapp01Controlpcviabluetoothenablemobile 091028150632-phpapp01
Controlpcviabluetoothenablemobile 091028150632-phpapp01
 
Control Pc Via Bluetooth Enable Mobile
Control Pc Via Bluetooth Enable MobileControl Pc Via Bluetooth Enable Mobile
Control Pc Via Bluetooth Enable Mobile
 
Controlpcviabluetoothenablemobile 091028150632-phpapp01
Controlpcviabluetoothenablemobile 091028150632-phpapp01Controlpcviabluetoothenablemobile 091028150632-phpapp01
Controlpcviabluetoothenablemobile 091028150632-phpapp01
 

Mehr von Emanuele Di Saverio

Programming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for AndroidProgramming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for AndroidEmanuele Di Saverio
 
Android 1.5 to 3.0: a compatibility journey
Android 1.5 to 3.0: a compatibility journeyAndroid 1.5 to 3.0: a compatibility journey
Android 1.5 to 3.0: a compatibility journeyEmanuele Di Saverio
 
Dive Into Android [ITA] - Long
Dive Into Android [ITA] - LongDive Into Android [ITA] - Long
Dive Into Android [ITA] - LongEmanuele Di Saverio
 
Whymca Dive into Android [ITA]
Whymca Dive into Android [ITA]Whymca Dive into Android [ITA]
Whymca Dive into Android [ITA]Emanuele Di Saverio
 

Mehr von Emanuele Di Saverio (6)

In a Material world
In a Material worldIn a Material world
In a Material world
 
Programming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for AndroidProgramming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for Android
 
The Android Experience
The Android ExperienceThe Android Experience
The Android Experience
 
Android 1.5 to 3.0: a compatibility journey
Android 1.5 to 3.0: a compatibility journeyAndroid 1.5 to 3.0: a compatibility journey
Android 1.5 to 3.0: a compatibility journey
 
Dive Into Android [ITA] - Long
Dive Into Android [ITA] - LongDive Into Android [ITA] - Long
Dive Into Android [ITA] - Long
 
Whymca Dive into Android [ITA]
Whymca Dive into Android [ITA]Whymca Dive into Android [ITA]
Whymca Dive into Android [ITA]
 

KĂźrzlich hochgeladen

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 

KĂźrzlich hochgeladen (20)

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 

Android Bluetooth Hacking Java Day2010 Eng

  • 1. Bluetooth Hacking Stefano Sanna - JUG Sardegna Emanuele Di Saverio - JUG Roma Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 01/30/2010
  • 2. Outline • Who we are • The relevance of Bluetooth on mobile devices • Android & Bluetooth: an unconsummated marriage • Happy hacking! • Bluetooth API for Android 1.x • Official API for Android 2.x • Demo: Android controls Arduino Bluetooth Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 3. Who we are • Stefano Sanna • Senior Solution Engineer Android @ beeweeb SpA • Author of the book “Java Micro Edition”, Hoepli (2007) • Main designer Bluetooth API for Android 1.x • Emanuele Di Saverio • Scrum Master and Senior Developer @ beeweeb SpA • SCMAD, SCJP • Committer easy-bluetooth spin-off for Android Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 4. Bluetooth on Android • early Android • Wrapper Java su Bluez • Android 0.9 • API Bluetooth disappears! • Android 1.x • No API for developers • Android 2.x • Exposes an API allowing discovery of remote devices, opening and accepting RFCOMM connections Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 5. The relevance of Bluetooth • Without a dedicated API is not possible to: • Discovery devices and services • Transfer files with Bluetooth FTP and OBEX • GPS connections, gamepads, medical devices • Remote control of embedded modules and sensor networks • Robotic application (i.e. LEGO Mindstorms) Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 6. A lot of devices out there... Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 7. Happy Hacking! Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 01/30/2010
  • 8. System service & Reflection • Bluetooth Service is accessible like every other Android Service: Object bluetoothService = context.getSystemService(“bluetooth”); Having the right Class, we can leverage la reflection to know (and invoke!) the methods: Class bluetoothServiceClass = bluetoothService.class; Method[] bluetoothMethods = bluetoothServiceClass.getMethods(); Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 9. Available Methods public android.bluetooth.BluetoothDevice(android.bluetooth.IBluetoothDevice) public boolean android.bluetooth.BluetoothDevice.cancelBondProcess(java.lang.String) public void android.bluetooth.BluetoothDevice.cancelDiscovery() public boolean android.bluetooth.BluetoothDevice.cancelPin(java.lang.String) public boolean android.bluetooth.BluetoothDevice.createBond(java.lang.String) public boolean android.bluetooth.BluetoothDevice.disable() public boolean android.bluetooth.BluetoothDevice.disconnectRemoteDeviceAcl(java.lang.String) public boolean android.bluetooth.BluetoothDevice.enable() public java.lang.String android.bluetooth.BluetoothDevice.getAddress() public int android.bluetooth.BluetoothDevice.getBluetoothState() public int android.bluetooth.BluetoothDevice.getBondState(java.lang.String) public java.lang.String android.bluetooth.BluetoothDevice.getCompany() public int android.bluetooth.BluetoothDevice.getDiscoverableTimeout() public java.lang.String android.bluetooth.BluetoothDevice.getManufacturer() public java.lang.String android.bluetooth.BluetoothDevice.getName() public int android.bluetooth.BluetoothDevice.getRemoteClass(java.lang.String) public java.lang.String android.bluetooth.BluetoothDevice.getRemoteCompany(java.lang.String) public [B android.bluetooth.BluetoothDevice.getRemoteFeatures(java.lang.String) public java.lang.String android.bluetooth.BluetoothDevice.getRemoteManufacturer(java.lang.String) public java.lang.String android.bluetooth.BluetoothDevice.getRemoteName(java.lang.String) public java.lang.String android.bluetooth.BluetoothDevice.getRemoteRevision(java.lang.String) public boolean android.bluetooth.BluetoothDevice.getRemoteServiceChannel(java.lang.String,short,android.bluetoot h.IBluetoothDeviceCallback) Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 10. Available Methods public android.bluetooth.BluetoothDevice(android.bluetooth.IBluetoothDevice) public boolean android.bluetooth.BluetoothDevice.cancelBondProcess(java.lang.String) public void android.bluetooth.BluetoothDevice.cancelDiscovery() O X! public boolean android.bluetooth.BluetoothDevice.cancelPin(java.lang.String) public boolean android.bluetooth.BluetoothDevice.createBond(java.lang.String) O E public boolean android.bluetooth.BluetoothDevice.disable() public boolean android.bluetooth.BluetoothDevice.disconnectRemoteDeviceAcl(java.lang.String) T L public boolean android.bluetooth.BluetoothDevice.enable() public java.lang.String android.bluetooth.BluetoothDevice.getAddress() public int android.bluetooth.BluetoothDevice.getBluetoothState() public int android.bluetooth.BluetoothDevice.getBondState(java.lang.String) P public java.lang.String android.bluetooth.BluetoothDevice.getCompany() public int android.bluetooth.BluetoothDevice.getDiscoverableTimeout() M public java.lang.String android.bluetooth.BluetoothDevice.getManufacturer() public java.lang.String android.bluetooth.BluetoothDevice.getName() O public int android.bluetooth.BluetoothDevice.getRemoteClass(java.lang.String) public java.lang.String android.bluetooth.BluetoothDevice.getRemoteCompany(java.lang.String) public [B android.bluetooth.BluetoothDevice.getRemoteFeatures(java.lang.String) C public java.lang.String android.bluetooth.BluetoothDevice.getRemoteManufacturer(java.lang.String) public java.lang.String android.bluetooth.BluetoothDevice.getRemoteName(java.lang.String) public java.lang.String android.bluetooth.BluetoothDevice.getRemoteRevision(java.lang.String) public boolean android.bluetooth.BluetoothDevice.getRemoteServiceChannel(java.lang.String,short,android.bluetoot h.IBluetoothDeviceCallback) Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 11. Permission • First Step: to access Bluetooth functionalities we need to declare two Permissions in the Manifest: <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 12. Remote device discovery LocalBluetoothDevice local = LocalBluetoothDevice.init(context); local.setListener(new LocalBluetoothDeviceListener() { public void scanStarted() { // scan has started... } public void scanCompleted(ArrayList<String> devices) { // scan is over } }); local.scan(); // start scan... Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 13. Open an RFCOMM socket from client RemoteBluetoothDevice dev = local.getRemoteBluetoothDevice(address); dev.setListener(new RemoteBluetoothDeviceListener() { public void paired() { // we open sockets and I/O streams... 3 BluetoothSocket socket = dev.openSocket(1); InputStream input = socket.getInputStream(); OutputStream output = socket.getOutputStream(); } public void pinRequested() { // show dialog for PIN input 2 } }); dev.pair(); 1 Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 14. Compatible devices • HTC Dream • HTC Magic • HTC Tattoo • Samsung Galaxy i7500 • Samsung Galaxy i5700 • Huawei U8220 • Sony-Ericsson XPERIA X10 Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 15. Bluetooth API for Android 1.x • The only opensource library (Apache 2.0) for accessing Bluetooth stack on Android 1.x • Features: • turn on/off Bluetooth • discovery of remote devices and RFCOMM bound to a service • opening of RFCOMM connections from client • Works without the necessity of root access • Check it out! • http://code.google.com/p/android-bluetooth Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 16. Bluetooth API for Android 1.x • More than 1000 downloads! • Used in commercial and free projects: • Inspired Bluetooth File Transfer by Medieval Software, the most succesful file transfer application on the Android Market • Used in Amarino (developed by MIT), first framework for controlling Arduino via an Android device • Used in GoPayment by Intuit Inc., for credit card payment via swiper and Bluetooth printer • Used in DUBwise project, for flying helicpoters :) Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 17. Main limitations • It’s not possible to register an SDP (Service Discovery Protocol) service on the database, even though is possible to create RFCOMM server socket • If a device inquiry is issue just after phone startup, the native call interferes with a system scan process and Bluetooth stack become unusable • Compatibility problems with HTC Hero Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 18. Permission on socket dbus Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 19. Android 2.x API • Android 2.0 : Bluetooth officially in the SDK! • Yay! But... • No direct control over pairing • No direct access to RFCOMM channels • No service discovery ...not so : • Android style: based on Intents and Receivers • Publish/Subscribe paradigm, a little clunky! Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 20. Discovery in Android 2.x BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); IntentFilter filter = new IntentFilter(); filter.addAction(BluetoothDevice.ACTION_FOUND); filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); //also can register for DISCOVERY_STARTED Action context.registerReceiver(receiver, filter); adapter.startDiscovery(); Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 21. BroadcastReceiver private final BroadcastReceiver receiver = new BroadcastReceiver() { public void onReceive(Context ctx, Intent intent) { final String action = intent.getAction(); if (action.equals(BluetoothDevice.ACTION_FOUND)) { BluetoothDevice device = (BluetoothDevice) intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); //process device } else if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)) { //done :o) } } }; Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 22. Socket e stream I/O //given a valid “BluetoothDevice”... UUID uuidOfTargetService = UUID.nameUUIDFromBytes(“2d26618601fb47c28d9f10b8ec891363”); BluetoothSocket socket = rbd.createRfcommSocketToServiceRecord(uuidOfTargetService); socket.connect(); InputStream input = socket.getInputStream(); OutputStream output = socket.getOutputStream(); .... socket.close(); Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 23. Android good practices • It’s important to keep in mind good practices of Android (and Java) programming!: • I/O operations always in a separate Thread • update UI via Handler • unregister Receivers before destroying Context Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 24. Is a separate library still useful? • In spite of Android 2.0 API, a Bluetooth library would be greatly useful! • Access to hidden features (via reflection) • Expose a simpler API • 1.x vs 2.x abstraction Retrocompatibility! • ....working out Easy Bluetooth • Check it out: http://android-bluetooth.googlecode.com/svn/ Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 25. Android controls Arduino • We want to use Android to control via Bluetooth a LED and read a temperature Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 26. Arduino • “Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. [...] It can sense the environment by receiving input from a variety of sensors and can affect its surroundings by controlling lights, motors, and other actuators. • Strictly MADE IN ITALY! • http://www.arduino.cc Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 27. Arduino Source int LED_PIN = 13; int LM35_PIN = 2; void setup() { Hardware: Serial.begin(115200); } pinMode(LED_PIN, OUTPUT); • Arduino Bluetooth • Prototype shield e breadboard void loop() { • LM35 Temperature Sensor if (Serial.available() > 0) { int inByte = Serial.read(); switch (inByte) { case '1': digitalWrite(LED_PIN, HIGH); Serial.write('1'); break; case '0': void readTemp() { digitalWrite(LED_PIN, LOW); int temp = analogRead(LM35_PIN); Serial.write('0'); temp= ( 5.0 * temp * 100.0) / 1024.0; break; Serial.write(temp); case 'r': } readTemp(); break; } } Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 28. Android Source // define commands... byte LED_ON_REQUEST = ‘1’; byte LED_OFF_REQUEST = ‘0’; byte READ_TEMPERATURE = ‘r’; [...] // in the Thread we send comandi and read responses... output.write(request); final int response = input.read(); if (request == 'r') { handler.post(new Runnable() { public void run() { String temp = Integer.toString(response); Toast.makeText(Controller.this, "LM35 Sensor: " + temp + "°C", 4000).show(); }); } Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 29. DEMO! Starring: Motorola Milestone (Android 2.0), HTC Magic (Android 1.6) and Arduino Bluetooth Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 01/30/2010
  • 30. Resources • Android • http://developer.android.com • http://source.android.com • Bluetooth API for Android 1.x e Easy Bluetooth • http://code.google.com/p/android-bluetooth • Arduino • http://www.arduino.cc Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 31. References • Stefano Sanna • gerdavax AT gmail DOT com • http://www.gerdavax.it • Emanuele Di Saverio • emanuele DOT disaverio AT gmail DOT com Stefano Sanna & Emanuele di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 30 gennaio 2010
  • 32. THANK YOU! Stefano & Emanuele & i rispettivi JUG! Stefano Sanna & Emanuele Di Saverio – JUG Sardegna / JUG Roma Javaday IV – Roma – 01/30/2010