我想自动检测我电脑周围的所有设备并向他们发送文件
我正在使用 brecham 和 inthehand dll,
这是我的代码:
BluetoothClient bc = new BluetoothClient();
BluetoothDeviceInfo[] info = null;
info = bc.DiscoverDevices(999);
foreach (BluetoothDeviceInfo device in info)
{
lstDevices.Items.Add(device.DeviceName + device.DeviceAddress);
device.Update();
device.Refresh();
device.SetServiceState(BluetoothService.ObexObjectPush, true);
if (!device.Authenticated)
{
// Use pin "0000" for authentication
if (!BluetoothSecurity.PairRequest(device.DeviceAddress, "0000")){
MessageBox.Show("Request failed");
}
}
var file = @"C:\1.jpg";
var uri = new Uri("obex://" + info[1].DeviceAddress + "/" + file);
var request = new ObexWebRequest(uri);
request.ReadFile(file);
var response = (ObexWebResponse)request.GetResponse();
MessageBox.Show(response.StatusCode.ToString());
//check response.StatusCode
response.Close();
}
但我收到消息“请求失败!” 请问有人能纠正我吗?
有人有想法吗?