Я пытаюсь узнать время автономной работы своих air pods pro с помощью приложения UWP и получаю сообщение об ошибке исключения, когда socket.ConnectAsync
вызывается Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
без дополнительной информации. Ниже вы можете найти источник:
private async Task ConnectToAirpods()
{
DeviceInformationCollection connectedDevices = await DeviceInformation.FindAllAsync(BluetoothDevice.GetDeviceSelectorFromConnectionStatus(BluetoothConnectionStatus.Connected));
foreach (DeviceInformation connectedDevice in connectedDevices)
{
if (connectedDevice.Name != "AirPods Pro")
continue;
BluetoothDevice bluetoothDevice = await BluetoothDevice.FromIdAsync(connectedDevice.Id);
RfcommDeviceServicesResult rfcommServices = await bluetoothDevice.GetRfcommServicesForIdAsync(
RfcommServiceId.FromUuid(new Guid("0000111e-0000-1000-8000-00805f9b34fb")), BluetoothCacheMode.Uncached);
if (rfcommServices.Services.Count > 0)
{
var service = rfcommServices.Services[0];
try
{
var socket = new StreamSocket();
await socket.ConnectAsync(service.ConnectionHostName, service.ConnectionServiceName);
}
catch (Exception ex)
{
}
}
}
}
Обновление # 1 Package.appxmanifest
<Capabilities>
<Capability Name="internetClient"/>
<Capability Name="internetClientServer"/>
<Capability Name="privateNetworkClientServer"/>
<DeviceCapability Name="bluetooth"/>
<DeviceCapability Name="bluetooth.rfcomm">
<Device Id="any">
<Function Type="name:serialPort"/>
</Device>
</DeviceCapability>
</Capabilities>
Обновление # 2
<DeviceCapability Name="bluetooth.rfcomm">
<Device Id="any">
<Function Type="serviceId:0000111e-0000-1000-8000-00805f9b34fb" />
</Device>
</DeviceCapability>