Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
181 | ligi | 1 | /********************************************************************************************************************************* |
2 | * * |
||
3 | * searches 4 Bluetooth Devices * |
||
4 | * * |
||
5 | * Author: Marcus -LiGi- Bueschleb * |
||
6 | * Project-Start: 9/2007 * |
||
7 | |||
8 | * Mailto: ligi@smart4mobile.de * |
||
9 | * Licence: Creative Commons / Non Commercial * |
||
10 | * Big Up: Holger&Ingo * |
||
11 | *********************************************************************************************************************************/ |
||
12 | |||
13 | import javax.bluetooth.*; |
||
14 | |||
15 | public class BTSearcher |
||
16 | implements DiscoveryListener |
||
17 | |||
18 | { |
||
19 | private LocalDevice m_LclDevice = null; |
||
20 | private DiscoveryAgent m_DscrAgent=null; |
||
21 | |||
22 | |||
23 | |||
24 | public boolean searching=true; |
||
25 | public boolean error=false; |
||
26 | public String err_log="none"; |
||
27 | |||
28 | |||
29 | public final int MAX_DEVICES=10; |
||
30 | |||
231 | ligi | 31 | public RemoteDevice[] remote_devices; |
181 | ligi | 32 | public int remote_device_count=0; |
33 | public String[] remote_device_name; |
||
34 | public String[] remote_device_mac; |
||
35 | |||
36 | |||
37 | public BTSearcher() |
||
38 | { |
||
39 | |||
231 | ligi | 40 | remote_devices=new RemoteDevice[MAX_DEVICES]; |
181 | ligi | 41 | remote_device_name=new String[MAX_DEVICES]; |
42 | remote_device_mac=new String[MAX_DEVICES]; |
||
43 | |||
231 | ligi | 44 | remote_device_count=0; |
181 | ligi | 45 | try |
46 | { |
||
47 | //First get the local device and obtain the discovery agent. |
||
48 | m_LclDevice = LocalDevice.getLocalDevice(); |
||
49 | m_DscrAgent= m_LclDevice.getDiscoveryAgent(); |
||
50 | |||
231 | ligi | 51 | m_DscrAgent.startInquiry(DiscoveryAgent.GIAC,this); |
181 | ligi | 52 | } |
53 | catch (BluetoothStateException ex) |
||
54 | { |
||
55 | error=true; |
||
56 | err_log+="Problem in searching the blue tooth devices\n" + ex; |
||
57 | |||
58 | } |
||
231 | ligi | 59 | |
181 | ligi | 60 | } |
61 | |||
62 | |||
63 | public void inquiryCompleted(int transID) { |
||
64 | |||
231 | ligi | 65 | try { |
66 | for(int i=0;i<remote_device_count;i++) |
||
67 | { |
||
68 | remote_device_name[i]=remote_devices[i].getFriendlyName(true); |
||
69 | remote_device_mac[i]=remote_devices[i].getBluetoothAddress(); |
||
181 | ligi | 70 | |
231 | ligi | 71 | } |
72 | } |
||
73 | catch (Exception e) |
||
74 | { |
||
75 | err_log+="Problem in searching the blue tooth devices"; |
||
76 | } |
||
181 | ligi | 77 | searching=false; |
78 | } |
||
79 | |||
80 | |||
231 | ligi | 81 | public void search_again() |
82 | { |
||
83 | } |
||
84 | |||
181 | ligi | 85 | //Called when device is found during inquiry |
86 | public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) |
||
87 | { |
||
88 | try |
||
89 | { |
||
90 | if (remote_device_count!=(MAX_DEVICES-1)) |
||
91 | { |
||
231 | ligi | 92 | remote_devices[remote_device_count]=btDevice; |
181 | ligi | 93 | remote_device_count++; |
94 | } |
||
95 | } |
||
96 | catch (Exception e) |
||
97 | { |
||
98 | err_log+=("Device Discovered Error: " + e); |
||
99 | } |
||
100 | |||
101 | } |
||
102 | |||
103 | |||
104 | public void serviceSearchCompleted(int transID, int respCode) |
||
105 | { } |
||
106 | |||
107 | public void servicesDiscovered(int transID, ServiceRecord[] records) |
||
108 | { } |
||
109 | |||
110 | |||
111 | |||
112 | } |