The WIFI_SERVICE must be looked up on the Application

来源:互联网 发布:淘宝外卖粮票是什么 编辑:程序博客网 时间:2024/06/01 11:56

编译错误

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]


解决办法:

WifiManager wifiManager = (WifiManager)getSystemService(WIFI_SERVICE);

修改成

WifiManager wifiManager = (WifiManager)getApplicationContext().getSystemService(WIFI_SERVICE);










阅读全文
0 0