Actually I'm trying to make my existing app compatible on Android-10 (Q). Below is how I set compile and target sdk versions in my build.gradle file--
android {
compileSdkVersion 29
buildToolsVersion '29.0.0'
defaultConfig {
applicationId "com.xyz.myapp"
minSdkVersion 17
targetSdkVersion 29
versionCode 83
versionName "83.0"
multiDexEnabled true;
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
}
and below are the support library dependencies I'm using after migrating my app to Android-X
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.multidex:multidex:2.0.0'
I'm done migrating my project to Android-X, also installed Android9.+ (Q) API-Level 29 from sdk manager and still I'm getting "Cannot resolve symbol 'ACCESS_BACKGROUND_LOCATION'" error. I request you to guide me to resolve this issue. Also please let me know if I can provide more details for the same. Thank you.
android.permission.GET_ACCOUNTS. Allows access to the list of accounts in the Accounts Service. The app uses this permission in an effort to find the device user's name when the support session is presented to a representative.
ACCESS_COARSE_LOCATION. Allows an app to access approximate location. String. ACCESS_FINE_LOCATION. Allows an app to access precise location.
If your app needs to access the user's location, you must request permission by adding the relevant Android location permissions to your app. Android offers two location permissions: ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION . The permission you choose determines the accuracy of the location returned by the API.
If your app requests either ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION, the system automatically adds ACCESS_BACKGROUND_LOCATION to the request.
If a user grants your app access to device location – either ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION – then upgrades their device from Android 9 to Android 10, the system automatically updates the set of location-based permissions granted to your app. The set of permissions that your app receives after the upgrade depends on its target SDK version and its defined permissions.
Read official guideline Privacy changes in Android 10
.
if you target SDK 29+ and want to access locations in the background, you should add below in manifest
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
private static final int PERMISSION_REQUEST_FINE_LOCATION = 99;
private static final int PERMISSION_REQUEST_BACKGROUND_LOCATION = 100;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
if (this.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
if (this.checkSelfPermission(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
if (this.shouldShowRequestPermissionRationale(android.Manifest.permission.ACCESS_BACKGROUND_LOCATION)) {
// Dialog for grant Permission
}
else {
// Dialog for Required permission
}
}
}
}
The error message to which you refer is related to the privacy policies related to permissions on Android. Android 10 introduces the ACCESS_BACKGROUND_LOCATION
permission. The API level 29 specifies that access to the location of the device in the background requires this permissions. For this you need to set the targetSdkVersion
or compileSdkVersion
to 29
or higher.
Try to make the permission explicit in the Manifest to get permissions in foreground and background
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With