Android: Send Image via Bluetooth
Posted by Ketan Parmar
Thursday, April 28, 2011
at 2:20 PM Labels: Android, Bluetooth
I assume that you have experience of developing Bluetooth application in Android. Android Bluetooth API is not supporting OBEX directly, means I can not push any file directly to any device. Android Bluetooth API provide basic functionalities like discovery, connection and data transfer using streams (InputStream and OutputStream).
Transferring file using Bluetooth need lot of coding. We need to manage device discovery, connection, IO etc.
Now I found very simple way to send file using Bluetooth. Android has build-in Bluetooth application which allow us to send file across the devices. Build-in Bluetooth Application use SharedPerference to manage queue for Incoming and Outgoing files.
I find the way to use same technique. Android Bluetooth application use ContentProvider to manage communication between storage and user interface. so I found the way that we can use it's functionality
Here is the code, Following 6 line allow you to send file using bluetooth, you required only two things 1. URI of file which you want to send 2. DeviceAddress.
ContentValues values = new ContentValues();
values.put(BluetoothShare.URI, "content://" + uritoSend);
Long ts = System.currentTimeMillis();
Description of above code.
1. Create object of ContentValue
2. put URI of file which you want to send
3. put DeviceAdddress, destination device address
4. put Direction, set outbound means you want to send the file.
5. time stamp which will display at Notification bar
6. put time stamp.
Note: Above code is useful only if we can have URI of file which we want to send. It is perfectly work for Images because we can get URI of images available in Gallery but If we want to send file from SDCard then it difficult because we can not get URI of file available in SDCard.