Bonjour,
J'essaie de faire un programme qui affiche le nom et l'addresse bluetooth de tout les périphériques bluetooth qui sont à portée. J'ai fait un essai mais il ne fonctionne pas, pouriez-vous m'aider un peu ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 import javax.bluetooth.BluetoothStateException; import javax.bluetooth.DeviceClass; import javax.bluetooth.DiscoveryAgent; import javax.bluetooth.DiscoveryListener; import javax.bluetooth.LocalDevice; import javax.bluetooth.RemoteDevice; import javax.bluetooth.ServiceRecord; public class BluetoothTest implements DiscoveryListener{ //variable utilisée pour la découverte de préphérique bluetooth private DiscoveryAgent agent; public BluetoothTest() throws BluetoothStateException{ LocalDevice local = LocalDevice.getLocalDevice(); agent = local.getDiscoveryAgent(); System.out.println("début de la recherche..."); agent.startInquiry(DiscoveryAgent.GIAC, this); synchronized (this) { try { this.wait(); } catch (Exception e) { e.printStackTrace(); } } } public void deviceDiscovered(RemoteDevice device, DeviceClass classe) { System.out.println("trouvé :"); try{ System.out.println("nom : "+device.getFriendlyName(false)); System.out.println("adresse : "+device.getBluetoothAddress()); System.out.println(); }catch(Exception e){ e.printStackTrace(); } } public void inquiryCompleted(int arg0) { System.out.println("fin de la recherche"); } public void serviceSearchCompleted(int arg0, int arg1) { } public void servicesDiscovered(int arg0, ServiceRecord[] arg1) { } public static void main(String[] arg){ try{ BluetoothTest bluetooth = new BluetoothTest(); }catch(Exception e){ e.printStackTrace(); } } }
Partager