Statistiques
| Branche: | Révision:

teotestbluetooth / TestXamConnections / TestXamConnections.Android / Receivers / BluetoothReceiver.cs @ 340558f2

Historique | Voir | Annoter | Télécharger (1,13 ko)

1 3fa496d6 Martin Toutant
using Android.Bluetooth;
2 3c62e059 Martin Toutant
using Android.Content;
3
using System;
4 3fa496d6 Martin Toutant
using TestXamConnections.Device;
5 3c62e059 Martin Toutant
6 91ef3e8c Martin Toutant
namespace TestXamConnections.Droid.Receivers
7 3c62e059 Martin Toutant
{
8
    public class BluetoothReceiver : BroadcastReceiver
9
    {
10
        public EventHandler<BluetoothDevice> OnBluetoothDeviceDiscovered;
11
        public EventHandler<string> OnScanFinished;
12 3fa496d6 Martin Toutant
13 3c62e059 Martin Toutant
        public override void OnReceive(Context context, Intent intent)
14
        {
15
            if (intent.Action.Equals(BluetoothDevice.ActionFound))
16
            {
17
                BluetoothDevice foundDevice = intent.GetParcelableExtra(BluetoothDevice.ExtraDevice) as BluetoothDevice;
18
                if (foundDevice != null)
19
                {
20 340558f2 martin.toutant
                    var btDevice = new InfoAppareil
21 3c62e059 Martin Toutant
                    {
22 340558f2 martin.toutant
                        AdresseMAC = foundDevice.Address,
23
                        Nom = foundDevice.Name
24 3c62e059 Martin Toutant
                    };
25
                }
26
                OnBluetoothDeviceDiscovered.Invoke(this, foundDevice);
27
            } else if (intent.Action.Equals(BluetoothAdapter.ActionDiscoveryFinished)) 
28
            {
29
                OnScanFinished.Invoke(this, "Finished");
30
            }
31
        }
32
    }
33
}