错误内容:
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);
网友评论