问题,如何启动Android蓝牙Socket连接?
我想实现一个应用程序,我可以通过蓝牙套接字编程发送数据(对象/文件),但我不知道从哪里开始,
我创建了
private ArrayAdapter
用于存储扫描的设备,在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论