Android 经典蓝牙发现没有提供MAC地址以外的详细信息
我需要集成Bluetooth Classic discovery并在手机和设备之间创建连接,但discovery device并未在Receiver中提供更多详细信息。我的代码是:Android 经典蓝牙发现没有提供MAC地址以外的详细信息,android,bluetooth,bluetooth-lowenergy,Android,Bluetooth,Bluetooth Lowenergy,我需要集成Bluetooth Classic discovery并在手机和设备之间创建连接,但discovery device并未在Receiver中提供更多详细信息。我的代码是: final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION
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();
}
}
}
代码表示它拥有最近发现的设备的
BluetoothDevice
实例。现在,按照开发人员指南,我们可以发现这个类有很多信息,可以使用它的方法请求这些信息
例如:
device.getAddress()
,以获取设备的计算机地址
device.getName()
,以获取设备的本地名称。有关蓝牙的重要内容是mac地址。一旦你得到mac地址,
1.您可以配对、连接、发送和接收数据
例如:
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(macAddress);
device.getName();
mSocket.connect(createRfcomSecureConnection);
您至少应该指定所需的详细信息。@VladyslavMatviienko,如示例所示?我希望每个字段都可用。例如,名称、Mac地址和其他数据。