1 package com.example.groom;
3 import android.bluetooth.BluetoothAdapter;
4 import android.bluetooth.BluetoothDevice;
5 import android.bluetooth.BluetoothSocket;
6 import android.os.Handler;
7 import android.os.Message;
8 import android.util.Log;
10 import java.io.BufferedReader;
11 import java.io.IOException;
12 import java.io.InputStream;
13 import java.io.InputStreamReader;
14 import java.io.OutputStream;
15 import java.util.ArrayList;
17 import java.util.UUID;
30 private static final String
TAG =
"_CommunicationGroom";
48 private BluetoothSocket
socket =
null;
59 Log.d(
TAG,
"CommunicationGroom() " + groom.getName());
61 this.peripheriqueGroom = groom;
62 this.nomPeripherique = groom.getName();
63 this.adressePeripherique = groom.getAddress();
71 Log.d(
TAG,
"Création nouvelle socket");
72 socket =
peripheriqueGroom.createRfcommSocketToServiceRecord(UUID.fromString(
"00001101-0000-1000-8000-00805F9B34FB"));
79 Log.d(
TAG,
"Erreur création socket");
83 Message msg = Message.obtain();
118 return socket.isConnected();
127 ArrayList<BluetoothDevice> grooms =
new ArrayList<BluetoothDevice>();;
128 Set<BluetoothDevice> devices;
130 BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
131 devices = bluetoothAdapter.getBondedDevices();
132 for (BluetoothDevice device : devices)
142 if(grooms.size() < 1)
143 Log.d(
TAG,
"getListeGrooms() aucun groom détecté !");
159 @Override
public void run()
169 Log.d(
TAG,
"Envoyer trame : " + trame);
171 catch (IOException e)
173 Log.d(
TAG,
"Erreur écriture socket");
176 Message msg = Message.obtain();
195 @Override
public void run()
203 Message msg = Message.obtain();
207 Log.d(
TAG,
"Connexion socket");
209 catch (IOException e)
211 Log.d(
TAG,
"Erreur connexion socket");
214 Message msg = Message.obtain();
240 @Override
public void run()
248 Message msg = Message.obtain();
252 Log.d(
TAG,
"Déconnexion socket");
254 catch (IOException e)
256 Log.d(
TAG,
"Erreur déconnexion socket");
259 Message msg = Message.obtain();
290 Log.d(
TAG,
"Démarre la réception");
303 if (trame.length() > 0)
305 Log.d(
TAG,
"Réception trame : " + trame);
306 Message msg = Message.obtain();
309 handlerUI.sendMessage(msg);
312 catch (IOException e)
314 Log.d(
TAG,
"Erreur lecture socket");
317 Message msg = Message.obtain();
325 catch (InterruptedException e)