使用 32 英尺通过蓝牙将文件传输到 iphone
tranfer file via bluetooth to iphone using 32feet
我正在尝试使用 32 英尺蓝牙将文件传输到我的 iphone,但似乎无法通过 ObexWebResponse。
我已经阅读了很多 post,但 none 的解决方案似乎对我有用。
我得到的错误是
// 连接失败
// 请求的地址在其上下文中无效 "address:Guid"
private BluetoothClient _bluetoothClient;
private BluetoothComponent _bluetoothComponent;
private List<BluetoothDeviceInfo> _inRangeBluetoothDevices;
private BluetoothDeviceInfo _hlkBoardDevice;
private EventHandler<BluetoothWin32AuthenticationEventArgs> _bluetoothAuthenticatorHandler;
private BluetoothWin32Authentication _bluetoothAuthenticator;
public BTooth() {
_bluetoothClient = new BluetoothClient();
_bluetoothComponent = new BluetoothComponent(_bluetoothClient);
_inRangeBluetoothDevices = new List<BluetoothDeviceInfo>();
_bluetoothAuthenticatorHandler = new EventHandler<BluetoothWin32AuthenticationEventArgs>(_bluetoothAutenticator_handlePairingRequest);
_bluetoothAuthenticator = new BluetoothWin32Authentication(_bluetoothAuthenticatorHandler);
_bluetoothComponent.DiscoverDevicesProgress += _bluetoothComponent_DiscoverDevicesProgress;
_bluetoothComponent.DiscoverDevicesComplete += _bluetoothComponent_DiscoverDevicesComplete;
ConnectAsync();
}
public void ConnectAsync() {
_inRangeBluetoothDevices.Clear();
_hlkBoardDevice = null;
_bluetoothComponent.DiscoverDevicesAsync(255, true, true, true, false, null);
}
private void PairWithBoard() {
Console.WriteLine("Pairing...");
bool pairResult = BluetoothSecurity.PairRequest(_hlkBoardDevice.DeviceAddress, null);
if (pairResult) {
Console.WriteLine("Success");
Console.WriteLine($"Authenticated equals {_hlkBoardDevice.Authenticated}");
} else {
Console.WriteLine("Fail"); // Instantly fails
}
}
private void _bluetoothComponent_DiscoverDevicesProgress(object sender, DiscoverDevicesEventArgs e) { _inRangeBluetoothDevices.AddRange(e.Devices); }
private void _bluetoothComponent_DiscoverDevicesComplete(object sender, DiscoverDevicesEventArgs e) {
for (int i = 0; i < _inRangeBluetoothDevices.Count; ++i) {
if (_inRangeBluetoothDevices[i].DeviceName == "Uranus") {
_hlkBoardDevice = _inRangeBluetoothDevices[i];
PairWithBoard();
TransferFile();
return;
}
}
// no devices found
}
private void _bluetoothAutenticator_handlePairingRequest(object sender, BluetoothWin32AuthenticationEventArgs e) {
e.Confirm = true; // Never reach this line
}
// not working
// transfers a file to the phone
public void TransferFile() {
string file = "E:\test.txt",
filename = System.IO.Path.GetFileName(file);
string deviceAddr = _hlkBoardDevice.DeviceAddress.ToString();
BluetoothAddress addr = BluetoothAddress.Parse(deviceAddr);
_bluetoothClient.Connect(BluetoothAddress.Parse(deviceAddr), BluetoothService.SerialPort);
Uri u = new Uri($"obex://{deviceAddr}/{file}");
ObexWebRequest owr = new ObexWebRequest(u);
owr.ReadFile(file);
// error:
// Connect failed
// The requested address is not valid in its context ...
var response = (ObexWebResponse)owr.GetResponse();
Console.WriteLine("Response Code: {0} (0x{0:X})", response.StatusCode);
response.Close();
}
配对和身份验证工作正常,我可以让 BluetoothService.Handsfree 为我打电话,但文件传输失败。不知道实际错误是什么,我尝试了几乎所有可用的服务,但没有成功。
你能帮我弄清楚这是怎么回事吗?这是我第一次尝试使用蓝牙服务,所以我还有很多东西要学。
是否可以通过蓝牙将文件从 iPhone 传输到 Windows 桌面?
但是,如果您需要从 Android 设备传输媒体文件(图像、视频等),您可以使用 ObexListener class 提供通过 32Feet 库为此目的,然后您可以简单地调用 _obexListener.GetContext() 方法,该方法将阻塞并等待传入连接。
接收到新连接后,您可以将接收到的文件保存到本地存储,如下例所示:
ObexListener _listener = new ObexListener();
_listener.Start();
// This method will block and wait for incoming connections
ObexListenerContext _context = _listener.GetContext();
// Once new connection is received, you can save the file to local storage
_context.Request.WriteFile(@"c:\sample.jpg");
注意:在 Windows 上使用 OBEX 时,确保禁用 "Bluetooth OBEX Service" Windows 服务,以免让它处理传入的 OBEX 请求,而不是所需的应用程序。
我离开了一段时间。并开始尝试使用 xamiren,但后来不得不创建一个虚拟 Mac,这样我就可以让苹果商店在我的 phone 上加载软件。从那里开始,xamerin 'should' 工作得很好,但它是另一个领域,还有很多东西需要弄清楚。
我正在尝试使用 32 英尺蓝牙将文件传输到我的 iphone,但似乎无法通过 ObexWebResponse。
我已经阅读了很多 post,但 none 的解决方案似乎对我有用。
我得到的错误是
// 连接失败
// 请求的地址在其上下文中无效 "address:Guid"
private BluetoothClient _bluetoothClient;
private BluetoothComponent _bluetoothComponent;
private List<BluetoothDeviceInfo> _inRangeBluetoothDevices;
private BluetoothDeviceInfo _hlkBoardDevice;
private EventHandler<BluetoothWin32AuthenticationEventArgs> _bluetoothAuthenticatorHandler;
private BluetoothWin32Authentication _bluetoothAuthenticator;
public BTooth() {
_bluetoothClient = new BluetoothClient();
_bluetoothComponent = new BluetoothComponent(_bluetoothClient);
_inRangeBluetoothDevices = new List<BluetoothDeviceInfo>();
_bluetoothAuthenticatorHandler = new EventHandler<BluetoothWin32AuthenticationEventArgs>(_bluetoothAutenticator_handlePairingRequest);
_bluetoothAuthenticator = new BluetoothWin32Authentication(_bluetoothAuthenticatorHandler);
_bluetoothComponent.DiscoverDevicesProgress += _bluetoothComponent_DiscoverDevicesProgress;
_bluetoothComponent.DiscoverDevicesComplete += _bluetoothComponent_DiscoverDevicesComplete;
ConnectAsync();
}
public void ConnectAsync() {
_inRangeBluetoothDevices.Clear();
_hlkBoardDevice = null;
_bluetoothComponent.DiscoverDevicesAsync(255, true, true, true, false, null);
}
private void PairWithBoard() {
Console.WriteLine("Pairing...");
bool pairResult = BluetoothSecurity.PairRequest(_hlkBoardDevice.DeviceAddress, null);
if (pairResult) {
Console.WriteLine("Success");
Console.WriteLine($"Authenticated equals {_hlkBoardDevice.Authenticated}");
} else {
Console.WriteLine("Fail"); // Instantly fails
}
}
private void _bluetoothComponent_DiscoverDevicesProgress(object sender, DiscoverDevicesEventArgs e) { _inRangeBluetoothDevices.AddRange(e.Devices); }
private void _bluetoothComponent_DiscoverDevicesComplete(object sender, DiscoverDevicesEventArgs e) {
for (int i = 0; i < _inRangeBluetoothDevices.Count; ++i) {
if (_inRangeBluetoothDevices[i].DeviceName == "Uranus") {
_hlkBoardDevice = _inRangeBluetoothDevices[i];
PairWithBoard();
TransferFile();
return;
}
}
// no devices found
}
private void _bluetoothAutenticator_handlePairingRequest(object sender, BluetoothWin32AuthenticationEventArgs e) {
e.Confirm = true; // Never reach this line
}
// not working
// transfers a file to the phone
public void TransferFile() {
string file = "E:\test.txt",
filename = System.IO.Path.GetFileName(file);
string deviceAddr = _hlkBoardDevice.DeviceAddress.ToString();
BluetoothAddress addr = BluetoothAddress.Parse(deviceAddr);
_bluetoothClient.Connect(BluetoothAddress.Parse(deviceAddr), BluetoothService.SerialPort);
Uri u = new Uri($"obex://{deviceAddr}/{file}");
ObexWebRequest owr = new ObexWebRequest(u);
owr.ReadFile(file);
// error:
// Connect failed
// The requested address is not valid in its context ...
var response = (ObexWebResponse)owr.GetResponse();
Console.WriteLine("Response Code: {0} (0x{0:X})", response.StatusCode);
response.Close();
}
配对和身份验证工作正常,我可以让 BluetoothService.Handsfree 为我打电话,但文件传输失败。不知道实际错误是什么,我尝试了几乎所有可用的服务,但没有成功。
你能帮我弄清楚这是怎么回事吗?这是我第一次尝试使用蓝牙服务,所以我还有很多东西要学。
是否可以通过蓝牙将文件从 iPhone 传输到 Windows 桌面?
但是,如果您需要从 Android 设备传输媒体文件(图像、视频等),您可以使用 ObexListener class 提供通过 32Feet 库为此目的,然后您可以简单地调用 _obexListener.GetContext() 方法,该方法将阻塞并等待传入连接。
接收到新连接后,您可以将接收到的文件保存到本地存储,如下例所示:
ObexListener _listener = new ObexListener();
_listener.Start();
// This method will block and wait for incoming connections
ObexListenerContext _context = _listener.GetContext();
// Once new connection is received, you can save the file to local storage
_context.Request.WriteFile(@"c:\sample.jpg");
注意:在 Windows 上使用 OBEX 时,确保禁用 "Bluetooth OBEX Service" Windows 服务,以免让它处理传入的 OBEX 请求,而不是所需的应用程序。
我离开了一段时间。并开始尝试使用 xamiren,但后来不得不创建一个虚拟 Mac,这样我就可以让苹果商店在我的 phone 上加载软件。从那里开始,xamerin 'should' 工作得很好,但它是另一个领域,还有很多东西需要弄清楚。