简体   繁体   中英

Capture files send over bluetooth in C#

I'm creating a WPF application for sending and receiving files over bluetooth. I'm using 32feet library for the same. I can send files using ObexObjectPush bluetooth service.

But when files are received using the technique, specified here , are not captured by my application, instead my computer captures it.

Here is my code:

  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
        }
    }

All I want to do is to capture all file received using bluetooth. Presently my system shows a popup for receiving file. I want to override this behaviour and want my application to receive it.

Any help in this will be highly appreciated.

The computer is capturing the received files because it has its own Bluetooth handler up and running and listening for requests.

You need to stop the " Bluetooth OBEX Service " Windows service on your computer, in order to prevent it from handling the received files instead of your WPF application.

NOTE: I prefer to disable the " Bluetooth OBEX Service " Windows service instead of stopping it, because it seems -at some circumstances- there are some other services cause this service to be started automatically again. By disabling it, you will avoid any future confusion.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM