Révision be694ed4 TestXamConnections/TestXamConnections.Android/Connection/BluetoothConnectionService.cs
TestXamConnections/TestXamConnections.Android/Connection/BluetoothConnectionService.cs | ||
---|---|---|
31 | 31 |
private readonly string sppUUID = "00001101-0000-1000-8000-00805f9b34fb"; |
32 | 32 |
|
33 | 33 |
public BluetoothConnectionService() |
34 |
{
|
|
34 |
{ |
|
35 | 35 |
bluetoothAdapter = BluetoothAdapter.DefaultAdapter; |
36 | 36 |
} |
37 | 37 |
|
38 | 38 |
// Pour le bluetooth, le paramètre de connection est l'addresse MAC |
39 |
public EventHandler<string> ConnectionFailedEvent { get; set; } |
|
40 |
public async Task Connect(Dictionary<string, string> param) |
|
39 |
public async Task<bool> Connect(Dictionary<string, string> param) |
|
41 | 40 |
{ |
42 | 41 |
try |
43 | 42 |
{ |
... | ... | |
45 | 44 |
// On annule le scan |
46 | 45 |
if (bluetoothAdapter.IsDiscovering) |
47 | 46 |
{ |
48 |
bluetoothAdapter.CancelDiscovery(); |
|
47 |
_ = bluetoothAdapter.CancelDiscovery();
|
|
49 | 48 |
} |
50 | 49 |
|
51 | 50 |
if (param.ContainsKey(ConnectionConstants.MAC_ADDR_KEY)) |
... | ... | |
57 | 56 |
// On ferme la connexion existante |
58 | 57 |
if (socket != null) |
59 | 58 |
{ |
60 |
await CloseConnection(); |
|
59 |
_ = await CloseConnection();
|
|
61 | 60 |
} |
62 | 61 |
|
63 | 62 |
// Creation du canal RFCOMM (non sécurisé) |
... | ... | |
76 | 75 |
listeningThread = new Thread(async delagate => await ListeningAsync()); |
77 | 76 |
listeningThread.Start(); |
78 | 77 |
} |
78 |
} else |
|
79 |
{ |
|
80 |
// L'addresse MAC n'a pas été spécifiée |
|
81 |
return false; |
|
79 | 82 |
} |
80 | 83 |
} |
81 | 84 |
catch (Exception) |
82 | 85 |
{ |
83 |
Application.SynchronizationContext.Post(_ => { ConnectionFailedEvent.Invoke(this, param[ConnectionConstants.MAC_ADDR_KEY]); }, null);
|
|
86 |
return false;
|
|
84 | 87 |
} |
88 |
return true; |
|
85 | 89 |
} |
86 | 90 |
|
87 | 91 |
public EventHandler<byte[]> DataReceivedEvent { get; set; } |
Formats disponibles : Unified diff