Android:蓝牙连接、套接字和线程
我目前正在开发一个 Android 项目,对于 Android 平台来说是个新手。这是我从一篇文章中得到的一个练习,其中我必须创建一个类似 twitter 的应用程序,以便一个 Android 平台可以写入另一个平台,并且它会自动更新。我正在使用 Android 蓝牙模拟器进行测试。
但在开始之前,我在启动蓝牙连接时遇到了一些困难,并尝试了几个教程,包括官方 Android API/示例。
我有一个名为“BlueTweetService”的类,其中有三个方法:configureBluetoothServerSocket
、connectToServerDevice
和 shutdownBluetoothServerSocket
。
在第一种方法 configureBluetoothServerSocket
中,我必须打开一个 BluetoothServerSocket
并使用属性 String BluetoothTweetName
和 UUID BlueTweetUuid
>。
我尝试创建/打开服务器套接字,但无论我做什么,都会出现错误。
如果有人可以帮助我编写如何创建/打开该服务器套接字的代码,我将非常感激。
如果我需要提供一些信息,请告诉我,我会发布它们。
真挚地 梅斯蒂卡
I’m currently working on a Android project and is very newbie to the Android platform. It’s an exercise I got from an article where I have to create a twitterlike application so that one Android platform can write to another and it automatically is updating. I’m using a Bluetooth emulator for Android to test.
But before I start with that I’ve facing some difficulties with the initiating a Bluetooth connection and have tried out several tutorials inclusive the official Android API / samples.
I got a class called “BlueTweetService” and within this I got three methods: configureBluetoothServerSocket
, connectToServerDevice
and shutdownBluetoothServerSocket
.
In the first method, configureBluetoothServerSocket
, I’ve to open a BluetoothServerSocket
and using the properties String BluetoothTweetName
and UUID BlueTweetUuid
.
I’ve tried to create / open the serversocket but I gives me errors no matter what I do.
I would really appreciate if someone could help me with the code how to create / open that serversocket.
If I need to provide some information, please let me know and I’ll post them.
Sincerely
Mestika
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想创建一个BluetoothServerSocket,请执行此操作
当您创建这样的套接字时,它将等待传入连接。您无法使用它来发送或接收消息。
If you want to create a BluetoothServerSocket do this
When you create such a socket it will wait for incoming connection. You could not use it for send or receive messages.