Statistiques
| Branche: | Révision:

teotestbluetooth / TestXamConnections / TestXamConnections.Android / Services / BluetoothService.cs @ 4af7febc

Historique | Voir | Annoter | Télécharger (1,434 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 Java.IO;
9
using Java.Util;
10
using System;
11
using System.Collections.Generic;
12
using System.Collections.ObjectModel;
13
using System.Linq;
14
using System.Text;
15
using System.Threading;
16
using System.Threading.Tasks;
17
using TestXamConnections.Droid.Receivers;
18
using TestXamConnections.Droid.Utils;
19
using TestXamConnections.Models;
20
using TestXamConnections.Services;
21

    
22
namespace TestXamConnections.Droid.Services
23
{
24
    public class BluetoothService : IBluetoothService
25
    {
26
        private readonly BluetoothAdapter bluetoothAdapter;
27

    
28
        public ObservableCollection<Device> FoundDevices = new ObservableCollection<Device>();
29
        public BluetoothService()
30
        {
31
            FoundDevices = new ObservableCollection<Device>();
32
            bluetoothAdapter = BluetoothAdapter.DefaultAdapter;
33
        }
34

    
35
        public ICollection<Device> GetBondedDevices()
36
        {
37
            ICollection<Device> ret = new ObservableCollection<Device>();
38
            foreach (BluetoothDevice bondedDevice in bluetoothAdapter.BondedDevices)
39
            {
40
                Device toAddItem = new Device
41
                {
42
                    MACAddress = bondedDevice.Address,
43
                    Name = bondedDevice.Name
44
                };
45
                ret.Add(toAddItem);
46
            }
47
            return ret;
48
        }
49
    }
50
}