【发布时间】:2015-08-27 05:13:43
【问题描述】:
我正在使用 android 的 Bluetoothgatt 示例应用程序。设备已连接,但 bluetoothdevice.getname() 返回 null。这只发生在 micromax mobile 上。 (它具有 Kitkat 操作系统和蓝牙 4.0 支持)。有没有从设备读取数据的解决方案?我可以在其他手机上获取设备名称和其他特征。
【问题讨论】:
标签: android bluetooth-lowenergy
我正在使用 android 的 Bluetoothgatt 示例应用程序。设备已连接,但 bluetoothdevice.getname() 返回 null。这只发生在 micromax mobile 上。 (它具有 Kitkat 操作系统和蓝牙 4.0 支持)。有没有从设备读取数据的解决方案?我可以在其他手机上获取设备名称和其他特征。
【问题讨论】:
标签: android bluetooth-lowenergy
试试下面的代码。
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;
}
}
【讨论】: