【问题标题】:Capture files send over bluetooth in C#捕获文件在 C# 中通过蓝牙发送
【发布时间】:2018-12-03 16:23:24
【问题描述】:

我正在创建一个 WPF 应用程序,用于通过蓝牙发送和接收文件。我正在使用 32feet 库。我可以使用 ObexObjectPush 蓝牙服务发送文件。

但是,当使用指定here 的技术接收文件时,我的应用程序不会捕获它,而是我的计算机会捕获它。

这是我的代码:

  private void Listener(CancellationTokenSource token)
    {
        try
        {
            while (true)
            {
                using (var client = _listener.AcceptBluetoothClient())
                {
                    if (token.IsCancellationRequested)
                    {
                        return;
                    }

                    using (var streamReader = new StreamReader(client.GetStream()))
                    {
                        try
                        {  
                           // ...  Custom operation
                          //....
                        }
                        catch (IOException ex)
                        {                               
                            client.Close();
                            break;
                        }
                    }
                }
            }
        }
        catch (Exception exception)
        {
            // todo handle the exception
        }
    }

我要做的就是捕获使用蓝牙接收的所有文件。目前我的系统显示一个接收文件的弹出窗口。我想覆盖此行为并希望我的应用程序接收它。

对此的任何帮助将不胜感激。

【问题讨论】:

  • streamReader 在这里做什么?我的意思是它不是在接收文件吗?
  • 它没有被触发,而是弹出一个窗口,显示它正在接收文件。
  • 您是否创建了 SenderBluetoothService?
  • 我从 android 设备而不是 WPF 应用程序发送数据。虽然,我为 WPF 创建的 SenderBluetoothService 成功地将数据发送到 android 设备。
  • 您使用哪些蓝牙驱动程序?如果是 BlueSoleil 或 Toshiba 则他们有内置的 OPP 服务器并接收文件。您必须先禁用内置服务。

标签: c# bluetooth 32feet obex


【解决方案1】:

计算机正在捕获接收到的文件,因为它有自己的蓝牙处理程序启动并运行并侦听请求。

您需要停止计算机上的“Bluetooth OBEX 服务”Windows 服务,以防止它处理接收到的文件而不是您的 WPF 应用程序。

注意:我更喜欢禁用“Bluetooth OBEX 服务”Windows 服务而不是停止它,因为似乎 - 在某些情况下 - 有一些其他服务会导致该服务再次自动启动.通过禁用它,您将避免任何未来的混乱。

【讨论】:

    猜你喜欢
    • 2021-09-22
    • 1970-01-01
    • 2012-02-14
    • 1970-01-01
    • 1970-01-01
    • 2011-09-01
    • 2014-11-15
    相关资源
    最近更新 更多