Example #1
0
        internal BluetoothDevice GetBondedDevice(string address)
        {
            IntPtr deviceInfo;
            int    ret = Interop.Bluetooth.GetBondedDeviceByAddress(address, out deviceInfo);

            if (ret != (int)BluetoothError.None)
            {
                Log.Error(Globals.LogTag, "Failed to get bonded device by address, Error - " + (BluetoothError)ret);
                BluetoothErrorFactory.ThrowBluetoothException(ret);
            }
            BluetoothDeviceStruct device = (BluetoothDeviceStruct)Marshal.PtrToStructure(deviceInfo, typeof(BluetoothDeviceStruct));

            return(BluetoothUtils.ConvertStructToDeviceClass(device));
        }
Example #2
0
        private void RegisterBondCreatedEvent()
        {
            _bondCreatedCallback = (int result, ref BluetoothDeviceStruct device, IntPtr userData) =>
            {
                if (_bondCreated != null)
                {
                    BluetoothError res = (BluetoothError)result;
                    _bondCreated(null, new BondCreatedEventArgs(res, BluetoothUtils.ConvertStructToDeviceClass(device)));
                }
            };
            int ret = Interop.Bluetooth.SetBondCreatedCallback(_bondCreatedCallback, IntPtr.Zero);

            if (ret != (int)BluetoothError.None)
            {
                Log.Error(Globals.LogTag, "Failed to set bond created callback, Error - " + (BluetoothError)ret);
            }
        }
Example #3
0
        internal IEnumerable <BluetoothDevice> GetBondedDevices()
        {
            List <BluetoothDevice> deviceList = new List <BluetoothDevice>();

            _bondedDeviceCallback = (ref BluetoothDeviceStruct deviceInfo, IntPtr userData) =>
            {
                Log.Info(Globals.LogTag, "Bonded devices cb is called");
                if (!deviceInfo.Equals(null))
                {
                    deviceList.Add(BluetoothUtils.ConvertStructToDeviceClass(deviceInfo));
                }
                return(true);
            };
            int ret = Interop.Bluetooth.GetBondedDevices(_bondedDeviceCallback, IntPtr.Zero);

            if (ret != (int)BluetoothError.None)
            {
                Log.Error(Globals.LogTag, "Failed to get bonded devices, Error - " + (BluetoothError)ret);
                BluetoothErrorFactory.ThrowBluetoothException(ret);
            }
            return(deviceList);
        }