安卓:如何使用蓝牙发送到多个设备的消息? [英] Android:how to send a message using bluetooth to multiple devices?

查看:134
本文介绍了安卓:如何使用蓝牙发送到多个设备的消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文本文件发送给使用以下code多台设备,

I send the text file to multiple devices using the following code,

ContentValues values = new ContentValues(); 
String filePath1   =Environment.getExternalStorageDirectory().toString()+"/filename.txt";
values.put(BluetoothShare.URI, Uri.fromFile(newFile(filePath1)).toString()); 
values.put(BluetoothShare.DESTINATION,itDevices.getAddress());               values.put(BluetoothShare.DIRECTION, BluetoothShare.DIRECTION_OUTBOUND); 
Long ts = System.currentTimeMillis(); 
values.put(BluetoothShare.TIMESTAMP, ts); 
Uri contentUri = getContentResolver().insert(BluetoothShare.CONTENT_URI, values);

我想同类型的code的用于发送消息。通过使用蓝牙API应用程序,当我尝试我把消息连接到多个设备首先发送到设备上,并发送消息到该设备并再次断开,并连接到另一台设备并以这种方式这正好将消息发送到另一台设备。

I want the same type of code for sending a message. By using the Bluetooth API application when i try to send the message to multiple devices first i connect to a device and send message to that device and again disconnect and connect to another device and send message to another device in this way this goes.

是否有可能由一个将消息发送到多个设备一个没有断开通信

Is it possible to send a message to multiple devices one by one without disconnect the communication ?

推荐答案

是的,我相信这是可能同时交换与多个Android的Bluetoooth设备的消息 - 无需断开和重新连接

Yes, I believe it is possible to exchange messages with multiple Android Bluetoooth devices simultaneously - without disconnecting and reconnecting.

离开了Android API抛开对于初学者来说,绝对蓝牙允许您连接到并同时与多个设备进行通信。所有的蓝牙连接发生在微微网,其中包括一个主站和最多7奴隶。设备可以是一个以上的微微网的一部分,但是这是低效的(两个微网的时机是不是协调),可以是不可靠的,所以如果你想连接到多个其他设备,你必须确保你是主人。

Leaving the Android API aside for starters, Bluetooth definitely allows you to connect to and communicate with multiple devices simultaneously. All Bluetooth connections happen in piconets which include a master and up to 7 slaves. A device can be part of more then one piconet but this is inefficient (the timing of the two piconets isn't coordinated) and can be unreliable, so if you want to connect to multiple other devices you must make sure you are the master.

我已经做了这样的事情用的BlueZ(在大多数Linux和Android设备,包括 AOSP ),所以我可以验证它是相当直接的,工作可靠。

I've done this sort of thing with BlueZ (the Bluetooth stack on most Linux and Android devices including AOSP) so I can verify that it is fairly straight-forward and works reliably.

不过,我只是做在Android上的一对一连接,因此如何控制主从分配有我不能肯定地说。相比Android普通的Linux提供更少的电源和控制,并提供没有办​​法直接读取或更改主从角色分配。

However, I've only done one-to-one connections on Android, so I can't say for sure how you control the master-slave assignment there. Android provides much less power and control compared to regular Linux, and it provides no way to directly read or change the master slave role assignment.

在理论上,你应该能够基于其有史以来端发起连接将是掌握规则控制的角色,但我也希望做一些测试,看看还有什么可能什么。我所关注的主要是来源于一种可能性,即客户端设备之一(即你希望成为奴隶)可能已经有一个连接,例如耳机或键盘,所以当它接收传入的连接请求可能要求切换到主角色,以便它可以将您的服务器添加到它的微微网。

In theory, you should be able to control the roles based on the rule that which-ever side initiates the connection will be the master, but I would want to do some testing to see what else might be going on. My concern comes mainly from the possibility that one of the client devices (that you expect to be a slave) might already have a connection to e.g. a headset or keyboard, so when it receives the incoming connection request it might request to switch to master role so it can add your server to its piconet.

我的建议是,当你正在测试,可以访问hcitool你的设备之一(例如Linux机器或一个植根Android)和做的 hcitool CON,它会给你当前连接的列表,我想这包括角色。 (hcitool是Linux的一个标准工具,并包括在AOSP)。我想你也可以只使用经验方法:如果你能够创造一大堆的可靠工作则没有多大意义它是如何工作的并发连接 - 只要确保你测试,其中一些设备有其它设备的现有连接的情况下

What I would suggest is, when you are testing, get access to hcitool on one of your devices (e.g. a Linux box or a rooted Android) and do 'hcitool con' and it will give you a list of the current connections and I think this includes the role. (hcitool is a standard tool on Linux and is included in AOSP.) I guess you could also just use the empirical approach: if you are able to create a bunch of simultaneous connections that work reliably then it doesn't matter much how it works - just make sure you test situations where some of the devices have existing connections to other devices.

抱歉回事,但我认为这是一个很好的问题,有兴趣从谁做到了这一点在Android上的人听到。我想我已经听说了多玩家游戏的蓝牙Android的 - 我不知道,如果这些工作可靠

Sorry about going on, but I think this is a good question and would be interested to hear from people who have done this on Android. I think I've heard of multi-player Bluetooth games for Android - I wonder if those work reliably.

这篇关于安卓:如何使用蓝牙发送到多个设备的消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆