Michal Štefanec Michal Štefanec - 1 year ago 120
Android Question

Location target permission 23

I'm using altbeacon library to monitor and range beacons. I've read your requesting permission page and just want to know, if I target location permission for API 23+ (), will scan works on devices with API < 23? I don't have real device, so can't test it. Or is there any way to not request location permission with device with API below 23? Thanks for your answers

Answer Source

Restating the core question:

If you build an app that has a minSdkVersion < 23 but the targetSdkVersion >= 23, what happens when you try to scan for bluetooth beacons?

Short answer: it works.

Longer answer:

  • The user permissions request won't happen. with a minSdkVersion < 23, The compiler will stop you from including a line of code like requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSION_REQUEST_COARSE_LOCATION);
 because it won't run on earlier Android versions. If you wrap it in an if statement like if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) it won't get executed. If you add annotations like @SuppressLint("NewApi") the app will crash when trying to execute the code.

  • The beacon scanning will just work, both in the foreground and the background, regardless of the fact that the user permissions have not been granted. Earlier Android versions can't request the permission from the user, so the app just behaves as if they have been granted.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download