我正在开发一个项目,该项目需要在带蓝牙的台式机/笔记本电脑上运行的Windows应用程序与Android手机通信才能共享文件。我希望能够从PC到手机以及从手机到PC获取文件。它可以通过两者发送或任何一个发送/接收来完成。
我在PC上使用.NET,在Android手机上使用Android Studio或Xamarin(Visual Studio)。
我查看了32feet SDK,我可以通过OBEX从PC发送文件,但我不得不接受Android手机上的文件。我想发送一个文件,要么把它放在手机上的一个目录中,要么在我的手机代码中手动处理它,并在Android上使用某种接收器。
我正在编写这两个应用程序......原生手机应用程序和Windows应用程序。
我真正喜欢做的是手机上的某种共享目录。手机应用程序会写入手机上的特定目录。 PC通过蓝牙轮询该目录,并在读取时从目录中删除文件。然后,PC应用程序将文件写入手机上的该目录,以便手机应用程序轮询/读取。
类似的任何例子?还是可以帮助我完成这项任务的东西?
.......
我看到了downvotes ...这里是我用来向手机发送文件的一些代码。我需要知道如何通过手机上的接收器自动接受这个并将文件写入手机上的磁盘......
Private Sub btnTestBeam1_Click(sender As Object, e As EventArgs) Handles btnTestBeam1.Click
Dim sbdd As New InTheHand.Windows.Forms.SelectBluetoothDeviceDialog
Dim ofdFileToBeam As New OpenFileDialog
sbdd.ShowAuthenticated = True
sbdd.ShowRemembered = True
sbdd.ShowUnknown = True
If sbdd.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
If ofdFileToBeam.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Cursor.Current = Cursors.WaitCursor
Dim theuri As New Uri("obex://" + sbdd.SelectedDevice.DeviceAddress.ToString() + "/" + System.IO.Path.GetFileName(ofdFileToBeam.FileName))
Dim request As New ObexWebRequest(theuri)
request.ReadFile(ofdFileToBeam.FileName)
Dim response As ObexWebResponse = CType(request.GetResponse(), ObexWebResponse)
MessageBox.Show(response.StatusCode.ToString())
response.Close()
Cursor.Current = Cursors.Default
End If
End If
End Sub
我正在寻找的是能够直接写入手机上的文件夹或如何通过手机上的应用程序接收文件。
我还需要能够通过手机回到PC上做同样的事情。
任何意见/建议都会有所帮助......
答案 0 :(得分:0)
帮助后人......
PC方面......
Dim connectserver As Thread
Dim mstream As Stream
Dim client As BluetoothClient
Dim bluelisten As BluetoothListener
Dim muuid As Guid = New Guid("fa87c0d0-afac-11de-8a39-0800200c9a66")
Dim serverstart As Boolean = False
Private Sub btnTestb1_Click(sender As Object, e As EventArgs) Handles btnTestb1.Click
If (serverstart) Then
updateui("server already started")
End If
connectasserver()
End Sub
Private Sub connectasserver()
connectserver = New Thread(New ThreadStart(AddressOf serverconnectedthread))
connectserver.Start()
End Sub
Public Delegate Sub SetText(text As String)
Private Sub updateui(mess As String)
If LabelTestb.InvokeRequired Then
LabelTestb.Invoke(New SetText(AddressOf updateui), mess)
Else
LabelTestb.Text = mess & vbCrLf & LabelTestb.Text
End If
End Sub
Private Sub serverconnectedthread()
Dim sent() As Byte
Dim recieved(1024) As Byte
serverstart = True
updateui("waiting for connections of clients\n")
bluelisten = New BluetoothListener(muuid)
bluelisten.Start()
client = New BluetoothClient()
client = bluelisten.AcceptBluetoothClient()
updateui("client has connected\n")
mstream = client.GetStream()
While (True)
Try
mstream.Read(recieved, 0, recieved.Length)
updateui("recieved: " + Encoding.ASCII.GetString(recieved))
sent = Encoding.ASCII.GetBytes(" hello world\n")
mstream.Write(sent, 0, sent.Length)
sent = Nothing
Catch except As IOException
updateui("client has been disconnected\n")
connectserver.Abort()
client.Close()
mstream.Flush()
End Try
End While
End Sub
Android方面的事情...... https://github.com/xamarin/monodroid-samples/tree/master/BluetoothChat
鉴于这两方面......我将能够在两个方向上完全按照我想要的方式在线路上传输字节。