What type is BluetoothDevice???
In this code, device works like a string (holding the UUID of the physical device) when i use it in Log() for LogCat. But I cannot assign it to a string variable (Eclipse complains that it is of type BluetoothDevice).
String action = intent.getAction();
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
Log.v(TAG, "Device="+device); //DISPLAYS "Device=58:17:1C:EB:E3:A8" IN LOGCAT
String d = device; // TYPE MISMATCH!
- How come a BluetoothDevice object is displayed by its UUID in LogCat, as if it were a string?
EDIT:
The getName() crash was caused by BluetoothDevice returning null first time, because I receive ACTION_DISCOVERY_STARTED from BluetoothAdapter. So that is solved. The mystery of why BluetoothDevice sometimes is a String remains.
The reason it shows in the log is that it implements
toString()(more info here) which allows it to be automatically converted to a string for logging.If you want the hardware address as a string to use in your logic, you should use
device.getAddressinstead, which is in a format that is less likely to change.