以编程方式通过蓝牙传输图像

时间:2012-04-17 12:15:53

标签: android bluetooth file-transfer

如何以编程方式在Android中使用蓝牙将图像文件从一个设备发送到另一个设备。我可以正确发送文本文件,但在尝试发送图像文件时显示错误。

示例代码在这里:

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);

此处url指的是图片的路径。

1 个答案:

答案 0 :(得分:3)

您可以将此代码用于此问题:

 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);