Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bluetooth File Transfer

I am developing a Bluetooth application based on the Bluetooth Chat Example from the Android Developer Site. I need to do File Transfer via Bluetooth. Can anybody help me out?

like image 603
vidit Avatar asked Jun 13 '11 04:06

vidit


People also ask

How do I transfer files through Bluetooth?

Android: Open the file manager and select files. Choose Share > Bluetooth. Then select a device.

Can Bluetooth be used to transfer files?

Go to the Settings of your phone, then go to Bluetooth. Once the name shows up, press on the name of the device to pair successfully. Go to the file you want to transfer, and click on the Share button.


2 Answers

In case of transferring the files you can make an explicit call to ACTION_SEND using intents as shown below.

You can send a file to a paired device through obex in a couple of ways:

With the ACTION_SEND intent, that will popup a menu with the application that can handle the file type you want to send, from which the user will need to select bluetooth, and then the device.

Intent i = new Intent(Intent.ACTION_SEND); i.setType("image/jpeg");    
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("/sdcard/file.jpg")); 
startActivity(Intent.createChooser(i, "Send Image"));

I think this will help u . :)

like image 170
Hussain Avatar answered Oct 22 '22 12:10

Hussain


Follow these steps:

  1. Read your source file to a byte array (buffer)
  2. Call the write method of your chat service instance passing the bytes to be sent:

    // mChatService is your Bluetooth chat service  
    mChatService.write(buffer);
    
  3. Edit the Handler for MESSAGE_WRITE and MESSAGE_READ cases

like image 23
sajjad sjj Avatar answered Oct 22 '22 13:10

sajjad sjj