蓝牙SerialPort与ObexFileTransfer

时间:2017-04-26 19:19:10

标签: c# android ios bluetooth 32feet

下午好。 我正在开发一个应用程序,假设通过蓝牙将文件从计算机传输到智能手机,但配对并不是我的预期。

32feets 图书馆配对:

BluetoothEndPoint remoteEndPoint = new BluetoothEndPoint(selecteddevice.DeviceAddress,BluetoothService.ObexFileTransfer); 

最后一个参数是蓝牙适配器GUID。如果我通过

喂它
  1. BluetoothService.SerialPort 。我只能连接到Iphone SE

  2. BluetoothService.ObexFileTransfer 。我只能连接Allview Soul Xtream Mini。 我也得到了一个我无法以任何方式连接的星系标签2。 我使用了一个catch,错误如下:

    • ex {"请求的地址在其上下文中无效4CBCA5CAA8A0:0000110600001000800000805f9b34fb"} System.Net.Sockets.SocketException
  3. 我做了一些研究,这就是我发现的: https://32feet.codeplex.com/wikipage?title=Errors

    配对代码:

    private void Connect()
          {
               SelectBluetoothDeviceDialog bldialog = new SelectBluetoothDeviceDialog();
               serviceClass = BluetoothService.SerialPort;
               bldialog.ShowAuthenticated = true;
               bldialog.ShowRemembered = true;
               bldialog.ShowUnknown = true;
    
               if (bldialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
               {
                    if (bldialog.SelectedDevice == null)
                    {
                         System.Windows.Forms.MessageBox.Show("No device selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                         return; 
                    }                       
                    BluetoothDeviceInfo selecteddevice = bldialog.SelectedDevice;
                    BluetoothEndPoint remoteEndPoint = new BluetoothEndPoint(selecteddevice.DeviceAddress, BluetoothService.ObexFileTransfer);
    
                    client = new BluetoothClient();
                    try
                    {
                         client.Connect(remoteEndPoint);
                    }
                    catch (SocketException ex)
                    {
                         return;
                    }
                    catch (ObjectDisposedException ex)
                    {
                         return;
                    }
                    catch (IOException ex)
                    {
                         return;
                    }
    
                    textBox.Text += string.Format("Connected to: {0}", selecteddevice.DeviceName);
                    textBox.Text += string.Format("Bluetooth Device Browser. Current Device: {0}", selecteddevice.DeviceName);
    
               }
          }
    

    蓝牙我正在使用华硕USB-BT400。 我可以做些什么来解决我的连接问题?

1 个答案:

答案 0 :(得分:0)

我解决了这个问题

       BluetoothDeviceInfo selecteddevice = bldialog.SelectedDevice;
                if (selecteddevice.DeviceName.ToLower().Contains("iphone"))
                     serviceClass = BluetoothService.SerialPort;
                else if (selecteddevice.DeviceName.ToLower().Contains("allview"))
                     serviceClass = new Guid("00001103-0000-1000-8000-00805f9b34fb");
                else serviceClass = BluetoothService.ObexFileTransfer;

另外,如果其他人对我如何连接到我的星系标签有任何想法我都在听,我也没有设法配对它。