Venkat
Venkat

Reputation: 3457

How to send files to all the connected devices in android using bluetooth?

I created the list that have device detected, and I want to send data to each device; The process is : one device sent data to first device and after disconnect first device and start to connect second device and sent the same data to second device and after disconnect this process until the last device in device list.

So does it possible to do that?

Upvotes: 4

Views: 3032

Answers (2)

MKJParekh
MKJParekh

Reputation: 34301

I have never done so but reading on different threads on Internet, I found that

You can send data using Bluetooth to multiple device.

For that you will have to connect with each device using different UUID.

You can go throught this post to get more understanding.

Upvotes: 2

Lucifer
Lucifer

Reputation: 29672

I am telling you logic part only, because frankly I haven't done this in Android platform.

  1. First Search all the Bluetooth device and collect their UUID and put it in a list.
  2. Now in a for look make connection with each device and send the file.

You can not send file to two device at a same time, because Bluetooth Connection is synchronized, so only one connection at a time is allowed.

You can use following code for sending file,

BluetoothDevice device; String filePath = Environment.getExternalStorageDirectory().toString() + "/data.txt";  
ContentValues values = new ContentValues(); 
values.put(BluetoothShare.URI, Uri.fromFile(new File(filePath)).toString()); 
values.put(BluetoothShare.DESTINATION, device.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);

Upvotes: 4

Related Questions