android wifi列表scanresult为空的问题

6.0之后关闭gps getscanresult方法获取不到wifi列表,但是原生系统设置里的wifi设置却可以获取到,为什么?有没有办法在关闭gps的情况下获取wifi列表,和原生设置里一样

https://blog.csdn.net/u011484134/article/details/52831854

public WifiManager mWifiManager;
//描述任何Wifi连接状态
private WifiInfo mWifiInfo;
private List mScanResult;

private final int SCAN = 1;
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what){
case SCAN :
Log.e("ConnectActivity","scan -----------");
mWifiManager.startScan();
mScanResult = mWifiManager.getScanResults();
listView.setAdapter(new MyAdapter(ConnectActivity.this,mScanResult));
mWifiInfo = mWifiManager.getConnectionInfo();
textView2.setText("当前网络情况:"+mWifiInfo.getBSSID()+"\n"+mWifiInfo.getMacAddress()+
"\n"+mWifiInfo.getSSID()+"\n"+mWifiInfo.getFrequency()+"\n"+mWifiInfo.getIpAddress());
mHandler.sendEmptyMessageDelayed(SCAN, 2000);
break;
}

    }
};


    查看mWifiManager.getScanResults();这句代码,你会发现

IWifiManager mService;

//其他代码

/**
* Return the results of the latest access point scan.
* @return the list of access points found in the most recent scan. An app must hold
* {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_COARSE_LOCATION} or
* {@link android.Manifest.permission#ACCESS_FINE_LOCATION ACCESS_FINE_LOCATION} permission
* in order to get valid results.
*/
public List getScanResults() {
try {
return
mService.getScanResults(mContext.getOpPackageName());
} catch (RemoteException e) {
return null;
}
}

    /**
 * 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();
}

wifi列表的获取跟GPS开关没有关联啊,wifi获取wifi服务之后扫描就可以获取到wifi列表。