|
android6.0以上扫描并获取wifi列表
发表于 2017-5-29 14:39:16
浏览:8097
|
回复:0
打印
只看该作者
[复制链接]
楼主
android6.0以上扫描并获取wifi列表需要打开GPS才有效,否则,获取到的wifi列表为空。
它的实现在:
- /**
- * Return the results of the most recent access point scan, in the form of
- * a list of {@link ScanResult} objects.
- * @return the list of results
- */
- public List<ScanResult> getScanResults(String callingPackage) {
- enforceAccessPermission();
- int userId = UserHandle.getCallingUserId();
- int uid = Binder.getCallingUid();
- boolean canReadPeerMacAddresses = checkPeersMacAddress();
- boolean isActiveNetworkScorer =
- NetworkScorerAppManager.isCallerActiveScorer(mContext, uid);
- boolean hasInteractUsersFull = checkInteractAcrossUsersFull();
- long ident = Binder.clearCallingIdentity();
- try {
- if (!canReadPeerMacAddresses && !isActiveNetworkScorer
- && !isLocationEnabled(callingPackage)) {
- return new ArrayList<ScanResult>();
- }
- if (!canReadPeerMacAddresses && !isActiveNetworkScorer
- && !checkCallerCanAccessScanResults(callingPackage, uid)) {
- return new ArrayList<ScanResult>();
- }
- if (mAppOps.noteOp(AppOpsManager.OP_WIFI_SCAN, uid, callingPackage)
- != AppOpsManager.MODE_ALLOWED) {
- return new ArrayList<ScanResult>();
- }
- if (!isCurrentProfile(userId) && !hasInteractUsersFull) {
- return new ArrayList<ScanResult>();
- }
- return mWifiStateMachine.syncGetScanResultsList();
- } finally {
- Binder.restoreCallingIdentity(ident);
- }
- }
复制代码
重点:
- if (!canReadPeerMacAddresses && !isActiveNetworkScorer
- && !isLocationEnabled(callingPackage)) {
- return new ArrayList<ScanResult>();
- }
复制代码
也就是说谷歌要求我们在定位的时候同时开启GPS的开关,当然这个有可能是谷歌考虑到自己的接口可以通过wifi列表定位,所以要求开发者要让用户有这个知情权吧。
|
|