我正在通过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()));
            }
            }
        }

}

我正在获取所有配对设备的MAC地址。我只希望将数据传输到的设备的MAC地址。

最佳答案

用这个:

BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);

10-07 13:22