【发布时间】:2012-08-16 22:50:43
【问题描述】:
我想通过蓝牙将文件发送到另一台设备。 我想以编程方式将文件发送到设备。有谁知道如何 我可以通过蓝牙 OPP 发送文件吗?
【问题讨论】:
我想通过蓝牙将文件发送到另一台设备。 我想以编程方式将文件发送到设备。有谁知道如何 我可以通过蓝牙 OPP 发送文件吗?
【问题讨论】:
你可以试试关注,
第一步在AndroidManifest.xml中添加蓝牙权限
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
第 2 步使用以下代码发送文件。
BluetoothDevice device; String filePath = Environment.getExternalStorageDirectory().toString() + "/data.txt";
ContentValues values = new ContentValues();
values.put(BluetoothShare.URI, Uri.fromFile(new File(filePath)).toString());
values.put(BluetoothShare.DESTINATION, device.getAddress());
values.put(BluetoothShare.DIRECTION, BluetoothShare.DIRECTION_OUTBOUND);
Long ts = System.currentTimeMillis(); values.put(BluetoothShare.TIMESTAMP, ts);
Uri contentUri = getContentResolver().insert(BluetoothShare.CONTENT_URI, values);
第3步你可以从链接下载BluetoothShare.java。
完成。
【讨论】: