Statistiques
| Branche: | Révision:

teotestbluetooth / TestXamConnections / TestXamConnections.Android / Services / BluetoothService.cs @ c478f8e5

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

1 3fa496d6 Martin Toutant
using Android.Bluetooth;
2 3c62e059 Martin Toutant
using System.Collections.Generic;
3
using System.Collections.ObjectModel;
4 3fa496d6 Martin Toutant
using TestXamConnections.Device;
5 91ef3e8c Martin Toutant
using TestXamConnections.Services;
6 3c62e059 Martin Toutant
7 91ef3e8c Martin Toutant
namespace TestXamConnections.Droid.Services
8 3c62e059 Martin Toutant
{
9
    public class BluetoothService : IBluetoothService
10
    {
11 4ca686e8 Martin Toutant
        private readonly BluetoothAdapter bluetoothAdapter;
12 3c62e059 Martin Toutant
13 3fa496d6 Martin Toutant
        public ObservableCollection<DeviceInfo> FoundDevices = new ObservableCollection<DeviceInfo>();
14 3c62e059 Martin Toutant
        public BluetoothService()
15
        {
16 3fa496d6 Martin Toutant
            FoundDevices = new ObservableCollection<DeviceInfo>();
17 3c62e059 Martin Toutant
            bluetoothAdapter = BluetoothAdapter.DefaultAdapter;
18
        }
19
20 3fa496d6 Martin Toutant
        public ICollection<DeviceInfo> GetBondedDevices()
21 3c62e059 Martin Toutant
        {
22 3fa496d6 Martin Toutant
            ICollection<DeviceInfo> ret = new ObservableCollection<DeviceInfo>();
23 3c62e059 Martin Toutant
            foreach (BluetoothDevice bondedDevice in bluetoothAdapter.BondedDevices)
24
            {
25 3fa496d6 Martin Toutant
                DeviceInfo toAddItem = new DeviceInfo
26 3c62e059 Martin Toutant
                {
27
                    MACAddress = bondedDevice.Address,
28
                    Name = bondedDevice.Name
29
                };
30
                ret.Add(toAddItem);
31
            }
32
            return ret;
33
        }
34
    }
35
}