列表大小为0,这是Android6.0中 WifiManager.getScanResults()的返回 我已经给了他许可(ACCESS_FINE_LOCATION和ACCESS_COARSE_LOCATION),但是列表的大小仍然是0。 我确定该应用在我的手机设置中有这些权限 - >应用。 你知道共鸣吗?任何解决方案?
答案 0 :(得分:2)
自Android 6.0起,权限行为已更改为运行时
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED){
requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
PERMISSIONS_REQUEST_CODE_ACCESS_COARSE_LOCATION);
//After this point you wait for callback in onRequestPermissionsResult(int, String[], int[]) overriden method
}else{
getScanningResults();
//do something, permission was previously granted; or legacy device
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions,
int[] grantResults) {
if (requestCode == PERMISSIONS_REQUEST_CODE_ACCESS_COARSE_LOCATION
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Do something with granted permission
mWifiListener.getScanningResults();
}
}