Back to project page roodroid.
The source code is released under:
Copyright (c) 2011, Jonathan Perichon & Lucas Gerbeaux Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"...
If you think the Android project roodroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package fr.utbm.roodroid.client; /*from w w w. ja v a 2s. c o m*/ import java.io.IOException; import java.util.UUID; import fr.utbm.roodroid.ApplicationManager; import fr.utbm.roodroid.ConnectionBluetooth; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothSocket; import android.util.Log; /** * ClientBluetooth * Extends Client in order to instantiate the ConnectionBluetooth. * * @author Jonathan Perichon <jonathan.perichon@gmail.com> * @author Lucas Gerbeaux <lucas.gerbeaux@gmail.com> * */ public class ClientBluetooth extends Client { private final BluetoothAdapter adapter; public ClientBluetooth(String id) throws Exception { super(id); adapter = BluetoothAdapter.getDefaultAdapter(); if (adapter == null) { throw new Exception("The device does not support Bluetooth"); } } public void connect(String address) throws IOException { BluetoothSocket socket = null; BluetoothDevice device = adapter.getRemoteDevice(address); boolean socketCreated = false; for (UUID uuid : ApplicationManager.getInstance().getUUIDs()) { try { socket = device.createRfcommSocketToServiceRecord(uuid); socketCreated = true; break; } catch (IOException e) { Log.e("ClientBluetooth", e.getMessage()); } } if (!socketCreated) { Log.e("ClientBluetooth", "socket not created"); throw new IOException("Error during the creation of the socket"); } socket.connect(); connection = new ConnectionBluetooth(this.handler, socket); new Thread(this.connection).start(); authenticate(); } }