ble device bluetoothdevice.getname()返回null [英] ble device bluetoothdevice.getname() returns null

查看:376
本文介绍了ble device bluetoothdevice.getname()返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用android的Bluetoothgatt示例应用程序.设备已连接,但bluetoothdevice.getname()返回null.这仅在micromax移动版上发生. (它具有Kitkat操作系统和蓝牙4.0支持).有什么解决方案可以从设备读取数据?我可以在其他手机上获取设备名称和其他特征.

i am using the android's Bluetoothgatt sample application. the device is connected but the bluetoothdevice.getname() returns null. this happens only on micromax mobile. (it is having Kitkat os and bluetooth 4.0 support). is there any solution to read the data from the device? i am able to get the device name and other characterstics on other phone.

推荐答案

尝试以下代码.

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;
        }
    }

这篇关于ble device bluetoothdevice.getname()返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆