编译错误
Error:Error: The WIFI_SERVICE must be looked up on the Application context or memory will leak on devices < Android N. Try changing to .getApplicationContext() [WifiManagerLeak]
- 1
原因
Android 7.0 在获取 WifiManager的时候需要使用.getApplicationContext(),如果未使用会造成内存泄露。
解决方法
原来的:
WifiManager wifiManager = (WifiManager)getSystemService(WIFI_SERVICE);
- 1
修改为:
WifiManager wifiManager = (WifiManager)getApplicationContext().getSystemService(WIFI_SERVICE);