DNwalter DNwalter - 5 months ago 62
Android Question

Android6.0 WifiManager.getScanResults()

The size of list is 0, which is the return of WifiManager.getScanResults() in Android6.0
I had given the permission(ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION) to him, but the size of list is still 0.
I sure the app has these permission in my phone Setting -> Apps.
Do you know the reson? Any Solutions?


As of Android 6.0, permission behaviour has changed to runtime

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},
    //After this point you wait for callback in onRequestPermissionsResult(int, String[], int[]) overriden method

   //do something, permission was previously granted; or legacy device

 public void onRequestPermissionsResult(int requestCode, String[] permissions,
         int[] grantResults) {
             && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
         // Do something with granted permission

Android 6.0, permission Documentation