如何在android中获取蓝牙连接设备的MAC地址

Anc*_*tal 6 android bluetooth

我在android中通过蓝牙发送图像,想要获取正在发送图像的设备的MAC地址.

请在下面找到我的代码.

private void bluetoothadd(){
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mBluetoothAdapter == null) {
        // Device does not support Bluetooth

        Log.e("Bluetooth ","not found");
    }

    if (!mBluetoothAdapter.isEnabled()) {
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivity(enableBtIntent);

        Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
        // If there are paired devices
        if (pairedDevices.size() > 0) {
            // Loop through paired devices
            for (BluetoothDevice device : pairedDevices) {


                Log.e("Mac Addressess","are:  "+mBluetoothAdapter.getRemoteDevice(device.getAddress()));
            }
            }
        }

}
Run Code Online (Sandbox Code Playgroud)

我正在获取所有配对设备的MAC地址.我只想要设备的MAC地址来传输数据.

小智 5

用这个:

BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
Run Code Online (Sandbox Code Playgroud)


ale*_*hka -3

尝试一下。

WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo info = manager.getConnectionInfo();
String address = info.getMacAddress();
Run Code Online (Sandbox Code Playgroud)