2012-04-17 58 views
1

如何以编程方式在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指的是图像的路径。

+0

'它显示error' - 我想我们希望看到的错误。 – 2012-04-17 12:21:12

+0

该错误是无法打开文件的出站信息27.在设备上显示蓝牙分享:文件未知文件未发送。 – 2012-04-17 12:30:01

回答

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

“BluetoothShare”现在无法访问....代码被隐藏...我们如何使用它?请回复。 – 2014-04-21 10:15:13

+0

不幸的是,这个答案并没有太大的帮助,因为'BluetoothShare'是未知的......你能详细说明一下吗? – Taifun 2016-05-14 21:38:45

+0

发现它同时,看到这个[Stackoverflow答案](http://stackoverflow.com/a/6531504/1545993) – Taifun 2016-05-14 22:20:10