0

i want to send files via Bluetooth to a another device. I want to send files to a device programmatically. Has anyone a idea how i can send files via Bluetooth OPP?

Arutha
  • 26,088
  • 26
  • 67
  • 80

1 Answers1

0

You can try following,

  • Step 1 add bluetooth permission in the AndroidManifest.xml

    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    
  • Step 2 use following code to send a 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);
    
  • Step 3 you can download BluetoothShare.java from the link.

done.

Lucifer
  • 29,392
  • 25
  • 90
  • 143