user5832543
user5832543

Reputation:

Android activity cannot resolve symbol ACCESS_BACKGROUND_LOCATION

I am trying to check permission for access to background location.

I have already visited this Cannot resolve Manifest.permission.ACCESS_FINE_LOCATION and I have examined all the provided solutions. None of them solved my issue.

Here is my code in Manifest file:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

and here is how I am trying to check the permission:

boolean backgroundLocationPermissionApproved =
       ActivityCompat.checkSelfPermission(this,
           permission.ACCESS_BACKGROUND_LOCATION)
           == PackageManager.PERMISSION_GRANTED;

I am getting this error:

error: cannot find symbol static checkBackGroundLocationPermissions

Any thoughts would be appreciated.

Upvotes: 6

Views: 4215

Answers (1)

user5832543
user5832543

Reputation:

I found the answer to my own question. So I am posting it here in case somebody else has the same problem.

Basically I was trying to ask permission for a background location tracking. It turned out that asking for permission is a requirement only if you have upgraded your app to work with Android 10 (Android Q). To check if your app needs permission, simply go to build.gradle file and check your targetSdkVersion. If it is anything below 29, like in my case which is 27, then you don't need to check permission for background location tracking. However, it is a good practice to upgrade your app to work with Android 10 by setting your targetSdkVersion to 29 and upgrading all your dependencies.

To some up this answer, I couldn't get ACCESS_BACKGROUND_LOCATION simply because the android.Manifest doesn't support that permission if you have not upgraded your app to sdk 29. For more information consider visiting the following page: https://developer.android.com/about/versions/10/privacy/changes

NOTE: As indicated by @LordParsley's comment:

  • Changing compileSdkVersion (not just targetSdkVersion) is needed.

Upvotes: 10

Related Questions