Firefly开源社区

打印 上一主题 下一主题

android6.0以上扫描并获取wifi列表

117

积分

1

威望

0

贡献

技术小白

积分
117

android6.0以上扫描并获取wifi列表

发表于 2017-5-29 14:39:16      浏览:5648 | 回复:0        打印      只看该作者   [复制链接] 楼主
android6.0以上扫描并获取wifi列表需要打开GPS才有效,否则,获取到的wifi列表为空。
它的实现在:
  1. /**
  2.      * Return the results of the most recent access point scan, in the form of
  3.      * a list of {@link ScanResult} objects.
  4.      * @return the list of results
  5.      */
  6.     public List<ScanResult> getScanResults(String callingPackage) {
  7.         enforceAccessPermission();
  8.         int userId = UserHandle.getCallingUserId();
  9.         int uid = Binder.getCallingUid();
  10.         boolean canReadPeerMacAddresses = checkPeersMacAddress();
  11.         boolean isActiveNetworkScorer =
  12.                 NetworkScorerAppManager.isCallerActiveScorer(mContext, uid);
  13.         boolean hasInteractUsersFull = checkInteractAcrossUsersFull();
  14.         long ident = Binder.clearCallingIdentity();
  15.         try {
  16.             if (!canReadPeerMacAddresses && !isActiveNetworkScorer
  17.                     && !isLocationEnabled(callingPackage)) {
  18.                 return new ArrayList<ScanResult>();
  19.             }
  20.             if (!canReadPeerMacAddresses && !isActiveNetworkScorer
  21.                     && !checkCallerCanAccessScanResults(callingPackage, uid)) {
  22.                 return new ArrayList<ScanResult>();
  23.             }
  24.             if (mAppOps.noteOp(AppOpsManager.OP_WIFI_SCAN, uid, callingPackage)
  25.                     != AppOpsManager.MODE_ALLOWED) {
  26.                 return new ArrayList<ScanResult>();
  27.             }
  28.             if (!isCurrentProfile(userId) && !hasInteractUsersFull) {
  29.                 return new ArrayList<ScanResult>();
  30.             }
  31.             return mWifiStateMachine.syncGetScanResultsList();
  32.         } finally {
  33.             Binder.restoreCallingIdentity(ident);
  34.         }
  35.     }
复制代码

重点:
  1. if (!canReadPeerMacAddresses && !isActiveNetworkScorer
  2.                     && !isLocationEnabled(callingPackage)) {
  3.                 return new ArrayList<ScanResult>();
  4.             }
复制代码

也就是说谷歌要求我们在定位的时候同时开启GPS的开关,当然这个有可能是谷歌考虑到自己的接口可以通过wifi列表定位,所以要求开发者要让用户有这个知情权吧。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

友情链接 : 爱板网 电子发烧友论坛 云汉电子社区 粤ICP备14022046号-2
快速回复 返回顶部 返回列表