Skip to content Skip to sidebar Skip to footer

Ble Device Bluetoothdevice.getname() Returns Null

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 havi

Solution 1:

Try below code.

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

Post a Comment for "Ble Device Bluetoothdevice.getname() Returns Null"