Programmatically transfer images through bluetooth

杀马特。学长 韩版系。学妹 提交于 2019-12-13 00:12:49

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/10191064/programmatically-transfer-images-through-bluetooth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!