简体   繁体   中英

C# 32feet obex bluetooth not supported by some phones

I have a project where a karaoke machine records the user and then lets the user connect to the machine via Bluetooth with his/her phone and download their recording. After a lot of reading, examples, documentations I tried using 32feet (the karaoke is written in C# .NET ), but the only way I found to send files is using ObexWebResponse and some phones don't have that service:

http://oi62.tinypic.com/153s8p5.jpg (picture from Bluetooth OBEX File Transfer)

This causes the program to throw and exception (this code is a sample I took from an answer here to just test sending video files before taking the dialogs out of the way and make it more automatic once the user pairs itself to the karaoke machine) :

    private void sendfile()
    {
        SelectBluetoothDeviceDialog dialog = new SelectBluetoothDeviceDialog();
        dialog.ShowAuthenticated = true;
        dialog.ShowRemembered = true;
        dialog.ShowUnknown = true;
        OpenFileDialog ofd = new OpenFileDialog();
        ofd.Title = "Select File";
        if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            string m_pin = "";
            Console.WriteLine(BluetoothSecurity.PairRequest(dialog.SelectedDevice.DeviceAddress, m_pin));

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                var uri = new Uri("obex://" + dialog.SelectedDevice.ToString() + "/" + ofd.FileName);
                var request = new ObexWebRequest(uri);
                request.ReadFile(ofd.FileName);
                var response = (ObexWebResponse)request.GetResponse(); // << THIS THROWS AN EXCEPTION WITH THE ADDITIONAL INFORMATION: CONNECT FAILED.
                response.Close();
            }
            else
            {
                MessageBox.Show("File Not Selected");
            }
        }
        else
        {
            MessageBox.Show("Device Not Selected");
        }
    }

Also the Debbuger shows: http://oi62.tinypic.com/e6rpkg.jpg

Is there an alternative to OBEX? Something that's compatible with every phone, or a method to mix with OBEX for those devices not compatible.

I have used the native Windows application (control panel > Devices and printers > Bluetooth devices > 'device name' > send file) to send a file so this isn't really a hardware related problem, if there is any solution even in other languages or libraries please give me a direction on how to make this happen.

Thank you in advance and for your time reading!

Not yet resorted to this for my own current PC/Bluetooth comms woes (currently working with 32feet and C#) however I did come across a native Microsoft library for C++: https://msdn.microsoft.com/en-us/library/windows/desktop/aa362932%28v=vs.85%29.aspx

As I say I've not tried it myself so can't vouch for it but it may be worth a look?

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