Ejemplo n.º 1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.WiFi_main);
            Current = this;

            // BLUETOOTH VERSION
            bluetoothAdapter = BluetoothAdapter.DefaultAdapter;
            if (bluetoothAdapter == null || !bluetoothAdapter.IsEnabled)
            {
                Intent enableBluetoothIntent = new Intent(BluetoothAdapter.ActionRequestEnable);
                StartActivityForResult(enableBluetoothIntent, REQUEST_ENABLE);
            }

            //SetUpDetailView();
            SetUpListView();
            SetUpDeviceNameOperations();
            SetScanListenState(listening: false, scanning: false, firstTimeSetup: true);

            GlobalBluetoothDeactivator = new CancellationTokenSource();

            // Rather than wait for the OnConnectionInfoAvailable, the way WiFiP2P does it, here we just set up the server and keep it running.
            Server = BluetoothMessageCenter.Server = new BluetoothServer(GlobalBluetoothDeactivator.Token);
            Server.Listen();

            KnownMACaddresses = Res.Storage.Get <HashSet <string> >(KnownMACaddressesKey) ?? new HashSet <string>();
            foreach (var macAddress in KnownMACaddresses)
            {
                var device = bluetoothAdapter.GetRemoteDevice(macAddress); // Returns a device with name = null if device not found in range
                OnPeerAvailable(device);                                   // Ignores all devices with null or empty name fields
                device = null;
            }
        }
Ejemplo n.º 2
0
 public ServerThread(BluetoothServer server, BluetoothSocket socket) : base(server.StopToken)
 {
     this.server = server;
     this.socket = socket;
 }