/** the intent that is used for initiating a handover transfer */
static final String ACTION_HANDOVER_SEND = "android.nfc.handover.intent.action.HANDOVER_SEND";
/**
* 通过蓝牙发送文件
*/
private void sendFile(Uri uri) {
super.grantUriPermission("com.android.bluetooth",uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
Intent intent = new Intent();
intent.setPackage("com.android.bluetooth");
intent.setType("image/*");
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
BluetoothDevice device = btAdapter.getRemoteDevice(SPF.getDeviceAddress());
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
intent.setAction(ACTION_HANDOVER_SEND);
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
sendBroadcast(intent);
}
通过向 Bluetooth 应用的 BluetoothOppHandoverReceiver 发送广播实现文件传输。
需要 OOP 开关配置为打开状态。