android - 经典蓝牙发现没有提供除 MAC 地址以外的详细信息
问题描述
我需要集成蓝牙经典发现并在手机和设备之间建立连接,但发现设备没有在接收器中提供更多详细信息。我的代码是:
final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
mBluetoothAdapter = bluetoothManager.getAdapter();
}else {
mBluetoothAdapter =BluetoothAdapter.getDefaultAdapter();
}
mBluetoothAdapter.startDiscovery();
public static class Receiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
if (BluetoothDevice.ACTION_FOUND.equals(intent.getAction())) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
Gson gson=new Gson();
LogUtils.errorLog("BC ","@@: "+gson.toJsonTree(device));
//callback.onDeviceFound(device);
} else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(intent.getAction())) {
context.unregisterReceiver(this);
// callback.onDiscoveryFinished();
}
}
}
解决方案
关于蓝牙的重要事情是mac地址。获得mac地址后, 1. 可以配对、连接发送和接收数据
例子:
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(macAddress);
device.getName();
mSocket.connect(createRfcomSecureConnection);
推荐阅读
- opencv - Bazel 从依赖项构建 `ios_framework` 导出标头
- python - 在无网格图像Python Opencv上画线
- javascript - 将参数从 JS 传递给 Struts2 Action 方法
- c# - 如何将参数放入 json 正文中?
- firebase - 访问与 Auth uid 匹配的集合的 Firestore 规则
- qt - 如何为 aarch64 架构编译 QT5.9 Webenginewidgets?
- caching - 如何在 Drupal 8/9 中控制通过 JSON:API 呈现的节点的可缓存性?
- python - 将预测的数字 y 值从由 PCA 权重构建的模型转换为布尔值
- bash - Bash使用awk读取csv文件并将输出保存在数组中
- node.js - localhost:5000 未运行 MERN 应用程序-MIME 错误