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.

Numa Fitness
  • 73
  • 1
  • 7

1 Answers1

0

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;
        }
    }
Gopi Krishna
  • 172
  • 1
  • 8
  • i tried the code but nothing is happening i think i am not able to use the code correctly can you please guide me also i saw this 08-27 11:15:12.054 11913-11913/com.example.android.bluetoothlegatt E/﹕ appName=com.example.android.bluetoothlegatt, acAppName=/system/bin/surfaceflinger 08-27 11:15:12.054 11913-11913/com.example.android.bluetoothlegatt E/﹕ 0 in my log cat – Numa Fitness Aug 27 '15 at 05:54
  • also i wanted to know is bluetooth a2dp compulsory for reading and writing data to ble devices – Numa Fitness Aug 27 '15 at 06:17