问题,如何启动Android蓝牙Socket连接?

发布于 2024-11-28 14:31:18 字数 1500 浏览 0 评论 0原文

我想实现一个应用程序,我可以通过蓝牙套接字编程发送数据(对象/文件),但我不知道从哪里开始,

我创建了

private ArrayAdapter; mNewDevicesArrayAdapter;

用于存储扫描的设备,在 BroadCastReceiver{ ...onReceive()... 我有这段代码..

if (BluetoothDevice.ACTION_FOUND.equals(action)) {
   // Get the BluetoothDevice object from the Intent                
     BluetoothDevice device = 
         intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

   // Add the name and address to an array adapter to show in a ListView
 mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
...}

String info = mNewDevicesArrayAdapter.getItem(0).toString();

视图中的最后 17 个字符

String address = info.substring(info.length() - 17);

System.out.println("In Auto   "+mNewDevicesArrayAdapter.toString());
System.out.println("In Auto    "+address);

// 获取设备 MAC 地址,这是 成功显示多个扫描设备...

现在我想将数据发送到阵列中存储的所有设备,但没有找到方法???

如何管理多个设备的 UUID?

我可以在其中从 http://developer.android 编写 AcceptThread、connectedThread、ConnectThread .com/guide/topics/wireless/bluetooth.html,在单独的类中或在我搜索设备的同一类中,因为在聊天示例中我可以看到 mNewDeviceArrayAdapter 在 DeviceListActivity 类中,而线程位于 BluetoothChatService 类中,

我还需要做什么?

如果我想接受来自多个设备的数据,就好像所有设备都运行我的应用程序一样,这样它们就可以相互发送和接收数据。

我希望,这个问题是读者可以理解的,那些知道解决方案的人很快就会指导我,

提前致谢 问候。

i want to implement an app where i can send data(object/file) through bluetooth Socket programming,, but m not getting the way where to start,

i have created

private ArrayAdapter<String> mNewDevicesArrayAdapter;

for storing scanned devices, in BroadCastReceiver{ ...onReceive()... where i have this code..

if (BluetoothDevice.ACTION_FOUND.equals(action)) {
   // Get the BluetoothDevice object from the Intent                
     BluetoothDevice device = 
         intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

   // Add the name and address to an array adapter to show in a ListView
 mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
...}

and

String info = mNewDevicesArrayAdapter.getItem(0).toString();

// Get the device MAC address, which is the last 17 chars in the View

String address = info.substring(info.length() - 17);

System.out.println("In Auto   "+mNewDevicesArrayAdapter.toString());
System.out.println("In Auto    "+address);

this is successfully showing multiple scanned devices...

now i want to send data to all devices store in array,, not getting the way???

how do i manage UUIDs for multiple devices ?

and where i can code AcceptThread, connectedThread, ConnectThread from http://developer.android.com/guide/topics/wireless/bluetooth.html, in separate class or in the same class where i am searching for devices, because in the chat example i can see that mNewDeviceArrayAdapter is in DeviceListActivity Class, while the Threads are in BluetoothChatService Class,

and what more i have to do,?

if i want to accept data from multiple devices, as if all devices have my app running, so they can send and receive data to one another.

I Hope, the question is understandable to the readers, and those who knows the solution will guide me soon,

Thanks in Advance
Regards.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文