Statistiques
| Branche: | Révision:

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

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

1
using Android.Bluetooth;
2
using Android.Content;
3
using System;
4
using TestXamConnections.Device;
5

    
6
namespace TestXamConnections.Droid.Receivers
7
{
8
    public class BluetoothReceiver : BroadcastReceiver
9
    {
10
        public EventHandler<BluetoothDevice> OnBluetoothDeviceDiscovered;
11
        public EventHandler<string> OnScanFinished;
12

    
13
        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
                    var btDevice = new InfoAppareil
21
                    {
22
                        AdresseMAC = foundDevice.Address,
23
                        Nom = foundDevice.Name
24
                    };
25
                }
26
                OnBluetoothDeviceDiscovered.Invoke(this, foundDevice);
27
            } else if (intent.Action.Equals(BluetoothAdapter.ActionDiscoveryFinished)) 
28
            {
29
                OnScanFinished.Invoke(this, "Finished");
30
            }
31
        }
32
    }
33
}