如何在Android中获取蓝牙连接设备的MAC地址 [英] how to get MAC Address of bluetooth connected device in android

查看:2769
本文介绍了如何在Android中获取蓝牙连接设备的MAC地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过android中的蓝牙发送图像,并希望获取将图像发送到的设备的MAC地址.

I am sending an image via bluetooth in android and want to fetch the MAC address of Device to which the image is being sent.

请在我的代码下面找到.

Please find below my code.

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地址.

I am getting all paired device's MAC Address. I want the MAC Address of a device only to which data is being transmitted.

推荐答案

使用此:

BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);

这篇关于如何在Android中获取蓝牙连接设备的MAC地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆