以编程方式检索MAC地址-Android [英] Retrieving MAC Address Programmatically - Android

查看:80
本文介绍了以编程方式检索MAC地址-Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以编程方式检索设备的MAC地址时遇到问题,在任何人提及其他帖子之前,我已经阅读了它们,例如: 如何以编程方式找到Android设备的MAC地址

I'm having an issue with retrieving the MAC address of the device programatically, before anyone mentions anything about other posts I have read them already such as: How to find MAC address of an Android device programmatically

但是我尝试在自己的应用程序中使用该代码,并使用简单的log.d对其进行了测试,结果发现它什么也没有返回.消息看看是否可行"显示,但没有其他消息.所以我假设mac地址为空.

however I tried using the code with my own application and tested it with a simple log.d, only to find that it is returning nothing. The message of "seeing if this works shows" but nothing else. So i am presuming the mac address is null.

Log.d("seeing if this works", macAddress2);

我所做的代码如下所示:

The code of what I have done is shown here:

//Set onclick listener for the Get Mac Address button
        getMac.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
                WifiInfo wInfo = wifiManager.getConnectionInfo();
                String macAddress2 = wInfo.getMacAddress();

                macAddress.setText(macAddress2);
            }
        });

推荐答案

您正在测试哪个Android版本?最新(2015年10月10日) Android M预览已阻止该应用获取Wifi和蓝牙的硬件标识符.

Which Android version are you testing on? The latest(10/2015) Android M preview has blocked the app from getting the hardware identifiers for Wifi and Bluetooth.

为了向用户提供更大的数据保护,从此版本开始,Android删除了使用Wi-Fi和Bluetooth API对应用的设备本地硬件标识符的编程访问. WifiInfo.getMacAddress()和BluetoothAdapter.getAddress()方法现在返回常数值02:00:00:00:00:00.

To provide users with greater data protection, starting in this release, Android removes programmatic access to the device’s local hardware identifier for apps using the Wi-Fi and Bluetooth APIs. The WifiInfo.getMacAddress() and the BluetoothAdapter.getAddress() methods now return a constant value of 02:00:00:00:00:00.

有一种解决方法,可以从/sys/class/net/wlan0/address读取Wifi MAC,但是在 Android N 中也将其作为

There is a workaround by reading the Wifi MAC from /sys/class/net/wlan0/address, which however will also be blocked in the Android N as claimed by Google.

这篇关于以编程方式检索MAC地址-Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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