her*_*110 5 java android mac-address
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地址为空。
Log.d("seeing if this works", macAddress2);
Run Code Online (Sandbox Code Playgroud)
我所做的代码如下所示:
//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);
}
});
Run Code Online (Sandbox Code Playgroud)
您正在测试哪个 Android 版本?最新的 (10/2015) Android M 预览版阻止了该应用获取 Wifi 和蓝牙的硬件标识符。
为了向用户提供更好的数据保护,从本版本开始,Android 删除了使用 Wi-Fi 和蓝牙 API 的应用程序对设备本地硬件标识符的编程访问。WifiInfo.getMacAddress() 和 BluetoothAdapter.getAddress() 方法现在返回一个常量值 02:00:00:00:00:00。
有一种解决方法是从 中读取 Wifi MAC /sys/class/net/wlan0/address,但是正如谷歌声称的那样,它也将在Android N 中被阻止。
你的清单中有这个吗?
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9545 次 |
| 最近记录: |