1

How to send a image file from one device to another using bluetooth in Android programmatically. I Can send text files correctly,but when trying to send image files it shows error.

Sample code is here:

ContentValues values = new ContentValues();

  values.put(BluetoothShare.URI, url);

  values.put(BluetoothShare.DESTINATION, deviceAddress);

  values.put(BluetoothShare.DIRECTION, BluetoothShare.DIRECTION_OUTBOUND);

  Long ts = System.currentTimeMillis();

  values.put(BluetoothShare.TIMESTAMP, ts);

  getContentResolver().insert(BluetoothShare.CONTENT_URI, values);

Here url refers to the path of the image.

Mike Fielden
  • 10,055
  • 14
  • 59
  • 99
Sharath Babu
  • 71
  • 2
  • 7

1 Answers1

3

you can use this code for this problem :

 File file=new File(imagePath);
 Uri uri=Uri.fromFile(file);

 ContentValues values = new ContentValues();

  values.put(BluetoothShare.URI, uri.toString());

  values.put(BluetoothShare.DESTINATION, deviceAddress);

  values.put(BluetoothShare.DIRECTION, BluetoothShare.DIRECTION_OUTBOUND);

  Long ts = System.currentTimeMillis();

  values.put(BluetoothShare.TIMESTAMP, ts);

  getContentResolver().insert(BluetoothShare.CONTENT_URI, values);
David
  • 72,686
  • 18
  • 132
  • 173
Danh DC
  • 1,246
  • 7
  • 17
  • "BluetoothShare" is not accessible now....code is hidden...how can we use it????? please reply. – Amit Shil Apr 21 '14 at 10:15
  • unfortunately this answer does not help very much, because `BluetoothShare` is unknown... can you elaborate? – Taifun May 14 '16 at 21:38
  • found it meanwhile, see this [Stackoverflow answer](http://stackoverflow.com/a/6531504/1545993) – Taifun May 14 '16 at 22:20