Get Connected device address bluetooth

how to get mac address of paired bluetooth device in android
bluetooth mac address scanner
pair bluetooth device with mac address
how to find mac address of bluetooth module hc-05
find bluetooth device
bluetooth device identifier
what can i do with a bluetooth address
get bluetooth mac address linux

I figured out we can get the connected bluetooth devices using BluetoothManager with the following code:

BluetoothManager manager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
    List<BluetoothDevice> connected = manager.getConnectedDevices(GATT);
    Log.i("Connected Devices: ", connected.toString()+"");

However, I get "cannot resolve symbol 'GATT'". What should be done?

Update:

package in.justrobotics.jrbluetoothcontrol;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import java.util.List;

public class TerminalActivity extends AppCompatActivity {

    TextView connectedDevices;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_terminal);
        connectedDevices=(TextView) findViewById(R.id.connected_devices);
        BluetoothManager manager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
        List<BluetoothDevice> connected = manager.getConnectedDevices(BluetoothGatt.GATT);
//        if (connected.size()>=1) {
        Log.i("Connected Devices: ", connected.get(0).toString() + "");
        connectedDevices.setText(connected.get(0).toString());
//        }
    }

}

My app is crashing with this error:

java.lang.RuntimeException: Unable to start activity ComponentInfo{in.justrobotics.jrbluetoothcontrol/in.justrobotics.jrbluetoothcontrol.TerminalActivity}: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2706)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767)
    at android.app.ActivityThread.-wrap12(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1514)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:163)
    at android.app.ActivityThread.main(ActivityThread.java:6221)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.get(ArrayList.java:411)
    at in.justrobotics.jrbluetoothcontrol.TerminalActivity.onCreate(TerminalActivity.java:24)
    at android.app.Activity.performCreate(Activity.java:6875)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2659)
    ... 9 more

Even though I have a speaker connected over BT.

Rather, it would be even better if someone could answer this question for me: Get address of connected device bluetooth

import static android.bluetooth.BluetoothProfile.GATT;

Android: Find Bluetooth Address, To find the Bluetooth address of your Android device, open the App drawer and tap Settings. Tap About Phone -- or About Tablet if your device is a tablet computer -- and then tap Status. The address is displayed in the Bluetooth Address field. android - Get Connected device address bluetooth - Stack Overflow I figured out we can get the connected bluetooth devices using BluetoothManager with the following code: BluetoothManager manager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE); List

I got into this yesterday and after giving a few try the following is somewhat working.

BluetoothManager myBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter mBluetoothAdapter = myBluetoothManager.getAdapter();
mBluetoothAdapter.enable();
Set s = mBluetoothAdapter.getBondedDevices();
Iterator it = s.iterator();
    while (it.hasNext()){
            BluetoothDevice d = (BluetoothDevice) it.next();
            System.out.println("device is "+d.getName());
            }          

Now the above only states which devices are bonded not necessarily connected. If I have only one headset bonded(paired) then.

int conState = mBluetoothAdapter.getProfileConnectionState(BluetoothProfile.HEADSET);
    System.out.println("connection state headset is "+conState);

If I have two same type of devices bonded, right now I do not have any idea, how to figure out which one is connected and which one is not.

Pair a Bluetooth Device and Retrieve the Bluetooth Device Address , The Bluetooth MAC address of a device is needed if you're trying to connect an app with a paired or connected Bluetooth device. Here's how  Turn on your Bluetooth audio device and make it discoverable. The way you make it discoverable depends on the device. Check the device or visit the manufacturer's website to learn how. On your PC, select Start > Settings > Devices > Bluetooth & other devices > Add Bluetooth or other device > Bluetooth.

connected.get(1) will return the second connected device. You should be using connected.get(0)

Also add a check for connected.size() because otherwise it will crash if you have no connected devices.

How Do I Find a Bluetooth Address?, if your Bluetooth Headphone Paired with Device, you can find Mac Address with of a device that was already in the paired list, but was not currently connected. What device are you using to pair the Bluetooth with? Under Control Panel, open the Devices and Printers section. Right-click on the HC-05 or HC-06 Bluetoothdevice, and select Properties. Click the Hardware menu, and then click Properties. Click the Details menu, and then select the Property as Bluetooth Device Address

How To Find Bluetooth MAC Address On Windows 10, When you connect a Bluetooth device on Windows 10, it appears with its manufacturer Duration: 1:32 Posted: Aug 30, 2018 Pair Bluetooth Device Turn on Bluetooth. In the Bluetooth menu, click Open Bluetooth Preferences. Mac immediately starts scanning for Bluetooth devices. You see the Bluetooth address of your device first, and then Turn Bluetooth off and on again, and reconnect your Bluetooth device. Disconnect

How do I find the Mac address of a paired device?, How can I find out the mac addresses of all bluetooth devices the adapter has detected? Some possiblilites: BluetoothCL (command line)  Turn on your Bluetooth device and make it discoverable. The way you make it discoverable depends on the device. Check the device info or website to find out more. On the taskbar, select the action center icon and make sure Bluetooth is turned on. In action center, select Connect, then pick your device. Follow any additional instructions.

How To Find Bluetooth MAC Address On Windows 10, There are some instances where you may need to find what the Bluetooth address is on your Android device. Here's how to locate it. Note: Before performing  Android Bluetooth List Paired Devices. By using BluetoothAdapter method getBondedDevices(), we can get the Bluetooth paired devices list. Following is the code snippet to get all paired devices with name and MAC address of each device.

Comments
  • Ok, no visible errors now. But connected.toString() returns null, what is the correct way to do it?
  • connected is a list of several BluetoothDevice items and I guess you want to take an item out of it, connected.get(position) gives you the BluetoothDevice item at index position. You can follow developer guide BluetoothDevice because a BluetoothDevice class has a lot of information, which one you want
  • App is now crashing, though I have a speaker device connected. Adding the crash log and changed code to the question.
  • Seems the index is out of bounds :/
  • Did that, still getting the error. connected.size() returns 0, why does that happen?
  • This happens when there are no devices unser GATT profile with STATE_CONNECTED try getDevicesMatchingConnectionStates for other states. Are you sure the device is connected? Also make sure the app has bluetooth permission.
  • Yes, I'm sure. Will share a screenshot