Skip to content Skip to sidebar Skip to footer

Android Bluetooth Push Files

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?

Solution 1:

You can try following,

  • Step 1 add bluetooth permission in the AndroidManifest.xml

    <uses-permissionandroid:name="android.permission.BLUETOOTH"/><uses-permissionandroid:name="android.permission.BLUETOOTH_ADMIN"/>
  • Step 2 use following code to send a file.

    BluetoothDevice device; StringfilePath= Environment.getExternalStorageDirectory().toString() + "/data.txt";  
    ContentValuesvalues=newContentValues(); 
    values.put(BluetoothShare.URI, Uri.fromFile(newFile(filePath)).toString()); 
    values.put(BluetoothShare.DESTINATION, device.getAddress()); 
    values.put(BluetoothShare.DIRECTION, BluetoothShare.DIRECTION_OUTBOUND); 
    Longts= System.currentTimeMillis(); values.put(BluetoothShare.TIMESTAMP, ts); 
    UricontentUri= getContentResolver().insert(BluetoothShare.CONTENT_URI, values);
    
  • Step 3 you can download BluetoothShare.java from the link.

done.

Post a Comment for "Android Bluetooth Push Files"