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 wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
替换成下面的:
WifiManager wifi = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
然而生成APK的时候还是报错:
Error:Error: The WIFI_SERVICE must be looked up on the Application context or memory will leak on devices < Android N. Try changing this to this.getApplicationContext() [WifiManagerLeak]
换成
WifiManager wifi = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
犯了错,总之要改,改之后呢,最好还是记录。因为这些难题在后来的日子还是会遇到。不妨到时候回过头看看自己当时记录的错误。毕竟是自己的错,资以改正。
纸上得来终觉浅,书到用时方恨少。希望对你有所帮助。
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/115072.html原文链接:https://javaforall.net