编程通过蓝牙传输图像 [英] Programmatically transfer images through bluetooth

查看:114
本文介绍了编程通过蓝牙传输图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从一台设备在Android中发送图片文件到另一个使用蓝牙编程。我正确地发送文本文件,但试图发送图像文件时,它会显示错误。

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.

样code是在这里:

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.

推荐答案

您可以使用此code这个问题:

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

这篇关于编程通过蓝牙传输图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆