我正在使用android的Bluetoothgatt示例应用程序。设备已连接但bluetoothdevice.getname()返回null。这只发生在micromax mobile上。 (它支持Kitkat操作系统和蓝牙4.0)。有没有解决方案从设备读取数据?我可以在其他手机上获取设备名称和其他特征。
答案 0 :(得分:0)
尝试以下代码。
public class BLEStateReceiver extends BroadcastReceiver {
String action = intent.getAction();
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if(device!= null && device.getType() != BluetoothDevice.DEVICE_TYPE_LE)
return;
if(action.equalsIgnoreCase(BluetoothDevice.ACTION_BOND_STATE_CHANGED)) {
int extra = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, 345);
switch (extra) {
case BluetoothDevice.BOND_BONDED:
BluetoothDevice bondedDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if(bondedDevice!= null) {
Log.d("TAG", "Bonded device name = " + bondedDevice.getName() + " Bonded Device address ="+bondedDevice.getAddress());
}
break;
}
}