I need to get the CONNECTED device name and address.
This is what I have tried so far and with it I'm able to get the paired devices list and addresses.
public class MainActivity extends AppCompatActivity {
TextView mBlue;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mBlue = (TextView) findViewById(R.id.Bluetooth);
String s = " ";
BluetoothAdapter ba = BluetoothAdapter.getDefaultAdapter();
Set <BluetoothDevice> devices = ba.getBondedDevices();
if (ba != null) {
for (BluetoothDevice device: devices)
s += device.getName() + "-" + device.getAddress() + "\n";
} else
s += "No address";
mBlue.setText(s.toString());
}
}
How to get the device address/name of connected Bluetooth device?
Please help me out with a clear code (both manifest and class code). I have seen other posts on SO but I can't make it out. Please help to solve this.