teotestbluetooth / TestXamConnections / TestXamConnections.Android / Receivers / BluetoothReceiver.cs @ 1fd64302
Historique | Voir | Annoter | Télécharger (1,27 ko)
1 |
using Android.App; |
---|---|
2 |
using Android.Bluetooth; |
3 |
using Android.Content; |
4 |
using Android.OS; |
5 |
using Android.Runtime; |
6 |
using Android.Views; |
7 |
using Android.Widget; |
8 |
using System; |
9 |
using System.Collections.Generic; |
10 |
using System.Linq; |
11 |
using System.Text; |
12 |
|
13 |
namespace TestXamConnections.Droid.Receivers |
14 |
{ |
15 |
public class BluetoothReceiver : BroadcastReceiver |
16 |
{ |
17 |
public EventHandler<BluetoothDevice> OnBluetoothDeviceDiscovered; |
18 |
public EventHandler<string> OnScanFinished; |
19 |
public override void OnReceive(Context context, Intent intent) |
20 |
{ |
21 |
if (intent.Action.Equals(BluetoothDevice.ActionFound)) |
22 |
{ |
23 |
BluetoothDevice foundDevice = intent.GetParcelableExtra(BluetoothDevice.ExtraDevice) as BluetoothDevice; |
24 |
if (foundDevice != null) |
25 |
{ |
26 |
var btDevice = new Models.Device |
27 |
{ |
28 |
MACAddress = foundDevice.Address, |
29 |
Name = foundDevice.Name |
30 |
}; |
31 |
} |
32 |
OnBluetoothDeviceDiscovered.Invoke(this, foundDevice); |
33 |
} else if (intent.Action.Equals(BluetoothAdapter.ActionDiscoveryFinished)) |
34 |
{ |
35 |
OnScanFinished.Invoke(this, "Finished"); |
36 |
} |
37 |
} |
38 |
} |
39 |
} |