如何在 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
是图片的路径。
最佳答案
你可以使用这段代码来解决这个问题:
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);
关于android - 通过蓝牙以编程方式传输图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10191064/