Vb.net 我如何通过蓝牙从我的应用程序向其他手机发送任何文件?

Vb.net 我如何通过蓝牙从我的应用程序向其他手机发送任何文件?,vb.net,windows-phone-8,Vb.net,Windows Phone 8,如何通过蓝牙将我的应用程序中的任何文件类型发送到其他手机 用vb和iam这个代码连接 PeerFinder.AlternateIdentities("Bluetooth:Paired") = "" Dim peers = Await PeerFinder.FindAllPeersAsync If peers.Count = 0 Then Return Else Dim pi As PeerInformation = peer

如何通过蓝牙将我的应用程序中的任何文件类型发送到其他手机

用vb和iam这个代码连接

    PeerFinder.AlternateIdentities("Bluetooth:Paired") = ""
    Dim peers = Await PeerFinder.FindAllPeersAsync

    If peers.Count = 0 Then

        Return

    Else

        Dim pi As PeerInformation = peers(4)

        Dim socket As New StreamSocket()
        Await socket.ConnectAsync(pi.HostName, "1")

end if

我在windows phone developer center中没有找到任何示例,说明如何通过蓝牙将文件发送到其他手机

看,这是一个示例windows phone应用程序,具有完整的通信示例

@user3078641欢迎使用
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)
        ' & "  A1 " & 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