【问题标题】:Programmatically transfer images through bluetooth通过蓝牙以编程方式传输图像
【发布时间】:2012-04-28 18:47:14
【问题描述】:

如何在 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指的是图片的路径。

【问题讨论】:

  • it shows error - 我想我们希望看到错误。
  • 错误是 Cant open file for outbound info 27. 在设备上它显示 BLUETOOTH SHARE: file unknown file not send.

标签: android bluetooth file-transfer


【解决方案1】:

您可以使用此代码解决此问题:

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

【讨论】:

  • “BluetoothShare”现在无法访问....代码被隐藏...我们如何使用它??????请回复。
  • 不幸的是,这个答案没有多大帮助,因为BluetoothShare 是未知的......你能详细说明一下吗?
  • 同时找到它,看到这个Stackoverflow answer
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-23
  • 1970-01-01
  • 2010-10-02
  • 1970-01-01
  • 1970-01-01
  • 2019-09-12
相关资源
最近更新 更多