0

maybe this is a stupid question but......

I would like to know why Android Stuio asks for permission check in a certain part of my code, even though I have already gone through the permission check some lines above...

I have enclosed a small screen cap with this part of the code to show you the exact situation...all the code that you can see on the picture is included in the only method existing in the code: OnCreate

enter image description here

codeKiller
  • 5,493
  • 17
  • 60
  • 115
  • This is asking because you are targeting app android M or higher. So some method that you need to check with if android.version>=M then {}else{...} – Vikas Tiwari Apr 28 '17 at 09:05
  • Firstly it is just a warning, not error. Also you should know that Android Stunio sometimes offers you wrong things. So first check if it is working, and only if it does not - start panic – Vladyslav Matviienko Apr 28 '17 at 09:08
  • Please refer to http://stackoverflow.com/a/35191441/2919811 – Lovekesh Apr 28 '17 at 09:14

1 Answers1

0

It is a warning generated by android studio. You code will still compile and run . But it is best practice to include the permission check before calling locationManager.requestLocationUpdates

Like:

     public boolean checkLocationPermission() {
        String permission = "android.permission.ACCESS_FINE_LOCATION";
        int res = this.checkCallingOrSelfPermission(permission);
        return (res == PackageManager.PERMISSION_GRANTED);
    }

use it like:

if (checkLocationPermission()) {
                locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 3000, 0, myLocationListener);
            }
rafsanahmad007
  • 23,683
  • 6
  • 47
  • 62
  • oh ok, thanks, since it is in red I thought it is an error, I will check that and mark it as answer if all goes right – codeKiller Apr 28 '17 at 10:22