Android7.0华为Mate9开发获取WiFi列表失败

关键代码

WifiManager wifiManager = (WifiManager) 
            context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
wifiManager.startScan();
List<ScanResult> results = wifiManager.getScanResults();

部分错误信息

W/WindowDecorActionBar: should not do the transition or the transition anim is null or it is running or the mContainer view is null or mContainer view hasn't been drawn to screen 
W/CfgFilePolicy: No config file found for:/themes/diff/icons
W/CfgFilePolicy: CFG_DIRS length : 9

分析过程
刚开始以为是layout在7.0又出问题了,因为其他机型都没问题,但是用Layout Inspector查看布局没有发现异常。用调试模式看到results一直等于0,百思不得其解。离开电脑,吃饭休息后,随手找度娘搜索一下mate9的wifi问题,第一个链接就解决问题了。原来Android7.0限制了权限,只有打开位置服务,才能获取到WiFi信息。另外还有部分三星的Android6.0手机也会出现这个问题,不一样的是这些手机要打开GPS。度娘给的链接如下
http://cn.ui.vmall.com/thread-11391904-1-3-4291.html

解决办法
打开位置服务!
打开位置服务!
打开位置服务!

获取WiFi列表成功
这里写图片描述

猜你喜欢

转载自blog.csdn.net/obarong/article/details/73302177