在JDK11中,该函数中的getApplicationContext()方法无法使用,需要使用其他方式获取Context对象。可以通过传递Context对象作为参数来解决这个问题。修改后的代码如下:

private String getFactoryMacAddress(Context context) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (wifiManager != null) { String macAddress = wifiManager.getFactoryMacAddresses(); if (macAddress != null && !macAddress.isEmpty()) { return macAddress; } } return "unknown"; }

其中,需要调用该函数的地方需要传递一个Context对象作为参数。

private String getFactoryMacAddress WifiManager wifiManager = WifiManager getApplicationContextgetSystemServiceContextWIFI_SERVICE; if wifiManager != null String macAddress

原文地址: https://www.cveoy.top/t/topic/bsKk 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录