Skip to content Skip to sidebar Skip to footer

How To Get Name Of The Connected Bluetooth Device On Android

I'm trying to get the name of the device that is connected to the Android phone running android Oreo. I was searching for an answer for the past two days, and none of them worked.

Solution 1:

here is the answer :

String name;
String address;
String threadName;
publicvoidcheckConnected()
{

       BluetoothAdapter.getDefaultAdapter().getProfileProxy(this, serviceListener, BluetoothProfile.HEADSET);
}

privateBluetoothProfile.ServiceListener serviceListener = newBluetoothProfile.ServiceListener()
{
    @OverridepublicvoidonServiceDisconnected(int profile)
    {

    }

    @OverridepublicvoidonServiceConnected(int profile, BluetoothProfile proxy)
    {

        for (BluetoothDevice device : proxy.getConnectedDevices())
        {
            name = device.getName();
            address = device.getAddress();
            threadName = Thread.currentThread().getName();
            Toast.makeText(MainActivity.this, name+" " + address+ threadName,  Toast.LENGTH_SHORT).show();
            txtName.setText(name + " " + address);
            Log.i("onServiceConnected", "|" + device.getName() + " | " + device.getAddress() + " | " + proxy.getConnectionState(device) + "(connected = "
                    + BluetoothProfile.STATE_CONNECTED + ")");
        }

        BluetoothAdapter.getDefaultAdapter().closeProfileProxy(profile, proxy);
    }
};

Solution 2:

Have you tried this?

BluetoothServerSocketbluetoothServerSocket= bluetoothAdapter.listenUsingRfcommWithServiceRecord("abc", uuid);          
BluetoothSocketbluetoothSocket= bluetoothServerSocket.accept();
BluetoothDevicedevice= bluetoothSocket.getRemoteDevice();
StringdeviceName= device.getName();

Post a Comment for "How To Get Name Of The Connected Bluetooth Device On Android"