Cannot resolve symbol 'ACCESS_BACKGROUND_LOCATION' - android

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.

When targeting Android 9 or lower
If your app requests either ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION, the system automatically adds ACCESS_BACKGROUND_LOCATION to the request.
Access when device is upgraded to Android 10
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" />
Runtime Permission
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" />

Related

background location not working when app in background xamarin forms android app when upgrade target api to 29

i have xamarin forms app that have tracking and fore ground service for background tracking working fine when set android target api level 28 but after upgrade it target api level 29 to upload app to play store no background location permission set to app so cannot get location when app in background.
and this manifest Permissions:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
and this run time request in main activity:
private static string[] _initialPerms ={
Manifest.Permission.AccessFineLocation,
Manifest.Permission.AccessCoarseLocation
};
if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessFineLocation) == Permission.Denied || ContextCompat.CheckSelfPermission(this, Manifest.Permission.Camera) == Permission.Denied)
{
RequestPermissions(_initialPerms, 1337);
}
thanks.
From Android 10, background location came as an independent resource. Apps have to request explicitly this permission besides the foreground one.
#TargetApi(29)
private fun Context.checkLocationPermissionAPI29(locationRequestCode : Int) {
if (checkSinglePermission(Manifest.permission.ACCESS_FINE_LOCATION) &&
checkSinglePermission(Manifest.permission.ACCESS_COARSE_LOCATION) &&
checkSinglePermission(Manifest.permission.ACCESS_BACKGROUND_LOCATION)) return
val permList = arrayOf(Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_BACKGROUND_LOCATION)
requestPermissions(permList, locationRequestCode)
}
private fun Context.checkSinglePermission(permission: String) : Boolean {
return ContextCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED
}
The permission ACCESS_BACKGROUND_LOCATION is new after Android 10.0 . Even if you have set the target version to Api 29 , but the version of support SDK in Xamarin.Android is still v28.x.x.x (Android 9.0) .So this enumeration is still unavailable in Xamarin.Android now . What you need is just to wait the update of the support SDK .
In your case , ACCESS_BACKGROUND_LOCATION will compatible with old version .
If the application apply for ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION, the system will automatically add a permission ACCESS_BACKGROUND_LOCATION during building.
===========================Update===============================
On Android 10 (API level 29) and higher, you must declare the ACCESS_BACKGROUND_LOCATION permission in your app's manifest in order to request background location access at runtime. On earlier versions of Android, when your app receives foreground location access, it automatically receives background location access as well.
<manifest ... >
<!-- Required only when requesting background location access on
Android 10 (API level 29) and higher. -->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
</manifest>
More info refer to android document here.

Android 10 request permission for ACTIVITY_RECOGNITION

I'm trying to comply with the Google requirements to request the permission ACTIVITY_RECOGNITION, for Android 10, but I don't seem to understand why there's no permission popup showing , like with the other permissions (ie, Location, storage,...)
The code I have is:
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACTIVITY_RECOGNITION) != PackageManager.PERMISSION_GRANTED) {
Log.d("TAG", "PERMISSION 'ACTIVITY_RECOGNITION' NOT GRANTED");
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACTIVITY_RECOGNITION},
MY_PERMISSIONS_ACTIVITY_RECOGNITION);
} else
{
Log.d("TAG", "PERMISSION 'ACTIVITY_RECOGNITION' GRANTED");
}
And I'm always ending up on the 'NOT GRANTED' flow, but the ActivityCompat.requestPermissions is not showing no popup!
Is there anything else I'm Missing ?
The manifest contains the
and the app.gradle
minSdkVersion 29
targetSdkVersion 30
Running out of ideas, any help would be welcome.
Just to add, I'm running this on my Pixel 2, with the latest firmware available 10.0.0 (QP1A.191105.004, Nov 2019)
check : Privacy changes in Android 10
From API 29(Android Q, Android 10)
Android App need permission in AndroidManifest.xml
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
Before API 29 AndroidManifest.xml
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
check : Google Fit APIs
And
If the system-auto grants the android.permission.ACTIVITY_RECOGNITION permission, your app retains the permission after you update your app to target Android 10. However, the user can revoke this permission at any time in system settings.
Thanks.

How to user PackageInstaller.SessionParams setGrantedRuntimePermissions method?

I'm building a system app (but not a signature app) to run as root in "kiosk mode". This app should install/uninstall third party apk's on runtime, according to the demand.
I need to install the third party app and immediately grant runtime permissions that the apk needs. After some research, I found the method (android.content.pm.PackageInstaller):
/**
* Sets which runtime permissions to be granted to the package at installation.
*
* #param permissions The permissions to grant or null to grant all runtime
* permissions.
*
* #hide
*/
#SystemApi
#RequiresPermission(android.Manifest.permission.INSTALL_GRANT_RUNTIME_PERMISSIONS)
public void setGrantedRuntimePermissions(String[] permissions) {
installFlags |= PackageManager.INSTALL_GRANT_RUNTIME_PERMISSIONS;
this.grantedRuntimePermissions = permissions;
}
As the annotation says, it can only be called if I declare INSTALL_GRANT_RUNTIME_PERMISSIONS on my app manifest. So, in spite I could not find this permission in (android.Manifest), I added it to manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx"
>
[...]
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.INSTALL_GRANT_RUNTIME_PERMISSIONS"/>
[...]
When I call the method on my code "params.setGrantedRuntimePermissions(new String[]{ Manifest.permission.ACCESS_COARSE_LOCATION });" I immediately receive an error from Android Studio saying that cannot resolve the method. It is easily explained because there's a #hide instruction there, so I tried to workaround, and call the method by Reflection:
String[] permissions = new String[]{ Manifest.permission.ACCESS_COARSE_LOCATION };
Method m = params.getClass().getMethod("setGrantedRuntimePermissions", new Class[] { String[].class } );
m.invoke(params, (Object)permissions);
But, in spite I have added the permission on Manifest, I still receive the security exception at runtime:
java.lang.SecurityException: You need the android.permission.INSTALL_GRANT_RUNTIME_PERMISSIONS permission to use the PackageManager.INSTALL_GRANT_RUNTIME_PERMISSIONS flag
Extra info:
. The app is installed under /system/priv-app
. Compilation details:
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.xxx"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
}
. I was using this lib (eu.chainfire.libsuperuser.Shell) to grant the permission and it works but I wonder If I can have it done without using shell:
Shell.SU.run("pm grant com.thirdparty.package android.permission.ACCESS_COARSE_LOCATION");
Any thoughts?

Permissions are granted by default

I'm not sure i fully understand this. So, for the <= 21 API version we can just use AndroidManifest.xml to request permissions, but Lollipop and higher APIs we have Requesting permission on runtime feature. So i'm using it with this simpe code:
if (Build.VERSION.SDK_INT >= 23) {
mPermissionsToBeAsked.clear();
for (String permission : AudioRecordingThread.PERMISSIONS_NEEDED) {
if (checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
mPermissionsToBeAsked.add(permission);
}
} ....
Then, if that list is not empty i'm requesting them :
if (mPermissionsToBeAsked.size() > 0) {
requestPermissions(mPermissionsToBeAsked.toArray(new String[0]), AUDIO_PERMISSIONS_REQUEST_CODE);
}
But, for some reason, on devices, for example, like Samsung Galaxy S7 with Android 6.0.1, all the permissions grandted by default when app is installed. So i want to know why, BUT, it's there is an even bigger concerne, when i go to my application in Application Manager and manually removing Microphone permision, in the app checkSelfPermission(permission) is still returning GRANTED. So the questions:
Why on devices with API level Lollipop and higher all permissions are still granted by default and above code won't add anything into mPersmissionToBeAsked?
Why if i manually removing permission with title MICROPHONE in Application manager checkSelfPermission(android.permission.RECORD_AUDIO) still returns GRANTED?
Just Cross verify in your app gradle file the targetsdk version is greater than 22.
defaultConfig {
// -----
targetSdkVersion 23
//----
}
If it is less than 23 than permission will automatically been granted to your app.
First of all it's Android M and above that handles permission granting. And that means you should have
targetSdkVersion 23
or above. Otherwise the system considers that the developper did not target this version, meaning that the developper does not check for permissions.

I got MISSING_PERMISSION issue Here maps Android

I'm trying an application just show Here map on screen. I've followed all of steps in document of Here + provided app_id, app_code, license key + provided 6 permissions in AndroidManifest.xml.
But It got the following issue:
"ERROR: Cannot initialize Map Fragment: MISSING_PERMISSION"
I'm using gradle 2.8, targetSdkVersion 23, compileSdkVersion 23
Android 6 / API 23 has a new permission system, that means you have to request critical permissions from the user.
See Android docs: https://developer.android.com/training/permissions/requesting.html
Just adding the critical permissions to the manifest is not enough anymore.
If you don't want to do this, you can still set traget API level to 22 and work in legacy mode, but to be more future proof, you should implement the new Android6 way of requesting permissions.
The critical permissions in the HERE SDK that you have to request are:
ACCESS_FINE_LOCATION and WRITE_EXTERNAL_STORAGE
Make sure you are using android runtime permission on for location access as from marshmallow onward all the OS need permission to run

Categories

Resources