Bluetooth rfcomm connection failure it throws exception saying deniedbysystem
Aryaveer Chaudhary
0
Reputation points
I am trying to make Bluetooth rfcomm connection with my mobile device but when i run this code it give me exception System.UnauthorizedAccessException: 'Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))'_
Guid HFP_Id = new Guid("0000111f-0000-1000-8000-00805f9b34fb");
DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(BluetoothDevice.GetDeviceSelectorFromPairingState(true));
var d2 = await DeviceInformation.FindAllAsync(
RfcommDeviceService.GetDeviceSelector(
RfcommServiceId.FromUuid(HFP_Id)));
if(d2.Count>0)
{
BTDevice.Text = d2[0].Name.ToString();
var desired_service = await RfcommDeviceService.FromIdAsync(d2[0].Id); //giving null
BlutooDevice = await BluetoothDevice.FromIdAsync(d2[0].Id);
var result = await BlutooDevice.GetRfcommServicesForIdAsync(RfcommServiceId.FromUuid(HFP_Id));
var desired_service2 = result.Services[0];
BTSocket = new StreamSocket();
await BTSocket.ConnectAsync(
desired_service2.ConnectionHostName,desired_service2.ConnectionServiceName,SocketProtectionLevel.BluetoothEncryptionAllowNullAuthentication
);
BTDevice.Text = "connected";
}
Capabilities
<Capabilities>
<DeviceCapability Name="bluetooth.rfcomm">
<Device Id="any">
<Function Type="serviceId:0000111f-0000-1000-8000-00805f9b34fb"/>
<Function Type="name:HandsfreeGateway"/>
</Device>
</DeviceCapability>
<DeviceCapability Name="bluetooth" />
</Capabilities>
Developer technologies | Universal Windows Platform (UWP)
3,040 questions
Developer technologies | C#
11,576 questions
Sign in to answer