FORUMS

How to get the address/name of connected Bluetooth device - Android

1 posts
Thanks Meter: 0
 
By yashwanth2412, Junior Member on 6th May 2020, 08:26 PM
Post Reply Email Thread
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.
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes