Error:(151) Error: The WIFI_SERVICE must be looked up on the Application context or memory will leak on devices

错误内容:

Error:(151) Error: The WIFI_SERVICE must be looked up on the Application context
 or memory will leak on devices < Android N. Try changing Utils.getContext() 
to Utils.getContext().getApplicationContext()  [WifiManagerLeak]

解决办法:
无线网络服务WIFI_SERVICE必须由Application的上下文去获取,否则的话,在7.0以下的设备中会发生内存泄漏。所以要在getSystemService方法之前加上getApplicationContext()

WifiManager mWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);  

你可能感兴趣的:(Error:(151) Error: The WIFI_SERVICE must be looked up on the Application context or memory will leak on devices)