如何通过蓝牙发送文件 [英] How can I send a file by bluetooth

查看:115
本文介绍了如何通过蓝牙发送文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在google和这个网站上找到了关于蓝牙的东西,但我无法理解任何事情。

我想要一个代码来通过蓝牙发送文件。

请帮助我。

Hi I in the google and this site and found sth about bluetooth but I couldn't understand any thing.
I want a code to send a file by bluetooth.
please help me.

推荐答案

你是只是在不费力的情况下寻找代码。



在这里,看一下C#中的这篇文章,关注它并用VB.NET编写:传输文件和监控C#中的蓝牙端口 [ ^ ]
You are just seeking for code without making any effort.

Here, have a look at this article in C#, follow it and write in VB.NET: Transferring files and monitoring Bluetooth ports in C# [^]


我最终自己做了。

我把这段代码放在这里。您可以使用此代码。

I finaly did that by myself.
I put this code here. you can use this code.
Public Class Form1
    Dim btClient As New InTheHand.Net.Sockets.BluetoothClient
    Dim SearchThread As System.Threading.Thread
    Dim response As InTheHand.Net.ObexWebResponse
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim x As String = "obex://" & CType(cboDevices.SelectedItem, InTheHand.Net.Sockets.BluetoothDeviceInfo).DeviceAddress.ToString & "/" + System.IO.Path.GetFileName(LBLFileName.Text)
            Dim theuri As New Uri("obex://" & CType(cboDevices.SelectedItem, InTheHand.Net.Sockets.BluetoothDeviceInfo).DeviceAddress.ToString & "/" + System.IO.Path.GetFileName(LBLFileName.Text))
            Dim request As New InTheHand.Net.ObexWebRequest(theuri)
            request.ReadFile(Application.StartupPath & "\FilesToSend\" & LBLFileName.Text)
            Dim s As DateTime
            s = Now
            response = CType(request.GetResponse(), InTheHand.Net.ObexWebResponse)
            ' & " ثانية وحالة الإرسال" & response.StatusCode.ToString
            '    Label4.Text = DateDiff(DateInterval.Second, s, Now) & " Sec"
            '    Label7.Text = CType(cboDevices.SelectedItem, InTheHand.Net.Sockets.BluetoothDeviceInfo).DeviceName.ToString
            If response.StatusCode.ToString.Trim = "BadRequest" Then
                Label1.Text = "Not success"
            ElseIf response.StatusCode.ToString.Trim = "OK, Final" Then
                Label1.Text = "Success"
            Else
                Label1.Text = "Error: : " & vbCrLf & _
                response.StatusCode.ToString.Trim
            End If
            response.Close()
        Catch ex As Exception
            MsgBox(Err.Description)
        End Try

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If CheckHardwareStatus() = False Then
            MsgBox("Please check BT..", MsgBoxStyle.Information + MsgBoxStyle.MsgBoxRtlReading)
            Exit Sub
        End If
        'SearchThread = New System.Threading.Thread(AddressOf SearchSub)
        'SearchThread.Priority = Threading.ThreadPriority.Highest
        'SearchThread.Start()
        SearchSub()
    End Sub

    Sub SearchSub()
        btClient = New InTheHand.Net.Sockets.BluetoothClient
        Dim s As DateTime
        s = Now
        Dim bdi As InTheHand.Net.Sockets.BluetoothDeviceInfo() = btClient.DiscoverDevices()
        LBlDuration.Text = "Duration: " & DateDiff(DateInterval.Second, s, Now) & " Sec"
        cboDevices.DataSource = bdi
        cboDevices.DisplayMember = "DeviceName"
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim of1 As New OpenFileDialog
        of1.Filter = "All files (*.*)|*.*"
        If of1.ShowDialog = Windows.Forms.DialogResult.OK Then
            LBLFileName.Text = System.IO.Path.GetFileName(of1.FileName)
            Dim FInfo As New IO.FileInfo(of1.FileName)
            LBLFileSize.Text = "File size : " & CType(CType(FInfo.Length / 1024, Integer), String) & " KB"
            Try
                System.IO.File.Copy(of1.FileName, Application.StartupPath & "\FilesToSend\" & System.IO.Path.GetFileName(of1.FileName), True)
            Catch ex As Exception
                MsgBox("Error:" & vbCrLf & _
                        ex.Message, MsgBoxStyle.Information + MsgBoxStyle.MsgBoxRight)
            End Try
        End If
    End Sub

    Function CheckHardwareStatus() As Boolean
        Dim br As InTheHand.Net.Bluetooth.BluetoothRadio = InTheHand.Net.Bluetooth.BluetoothRadio.PrimaryRadio
        If Not br Is Nothing Then
            If br.Mode = InTheHand.Net.Bluetooth.RadioMode.Discoverable Then
                Return True
            ElseIf br.Mode = InTheHand.Net.Bluetooth.RadioMode.Connectable Then
                Return True
            ElseIf br.Mode = InTheHand.Net.Bluetooth.RadioMode.PowerOff Then
                Return True
            End If
        Else
            Return False
        End If
    End Function
End Class





现在我也有更多的问题。



此代码发送文件但我想发送一个字符串作为短信



Now I have a more proble too.

this code send a file but I want to send a string as a sms


此代码适用于非常古老的bluetoot h版



如果我想将文件发送到新的Android手机我该怎么办?
this code work with very old bluetooth version

if i want to send a file to new android cellphone what should i do ?


这篇关于如何通过蓝牙发送文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆