1
我想自動檢測周圍的我的電腦的所有設備和文件發送給他們通過藍牙發送文件在C#應用程序
我使用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();
}
但我收到消息「請求失敗!」 請誰能糾正我?
任何人都有想法?
感謝您的代碼,這樣的好大塊!我只是想補充一點,你需要從Nuget安裝32feet.NET庫 - 它會將必要的InTheHand.Net.Personal.dll添加到項目中。 – CatCap
謝謝......它爲我工作.... tooooo –