Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

!important Android 12 new approximate location and precise location #235

Closed
bhandaribhumin opened this issue Sep 20, 2021 · 4 comments
Closed
Labels

Comments

@bhandaribhumin
Copy link

bhandaribhumin commented Sep 20, 2021

Feature Request

precise location work expectedly but when user select approximate location got error

getCurrentPosition() :

PositionError {code: 1, message: "Illegal Access"}	
code: 1	
message: "Illegal Access"	
__proto__: Object

Motivation Behind Feature

should solve current position coords.

It will requested both permission :
Screenshot: 1 user need to choose approximate location or precise location from popup

Screenshot 2021-09-20 at 11 33 56 AM

Screenshot: 2 expected behaviour only view precise location popup

Screenshot 2021-09-20 at 11 36 30 AM

Feature Description

Android BETA change log:

https://developer.android.com/about/versions/12/approximate-location#user-choice-approximate-precise

Alternatives or Workarounds

Not found workaround yet but observe some points:

New location changes might need fixes from both ts and plugin side
Plugin Changes : Handle Fine location not requested, send a new message
TS Changes : Handle this updated message from plugin

@breautek
Copy link
Contributor

breautek commented Sep 20, 2021

I believe this plugin is already compatible. It seems like if you request FINE location, then starting API 31, you must also request COARSE permission at the same time.

If your app targets Android 12 and you request the ACCESS_FINE_LOCATION permission, you must also request the ACCESS_COARSE_LOCATION permission. You must include both permissions in a single runtime request. If you try to request only ACCESS_FINE_LOCATION, the system ignores the request and logs the following error message in Logcat: ACCESS_FINE_LOCATION must be requested with ACCESS_COARSE_LOCATION.

The reason why I believe this plugin is already compatible is because we old an array containing both of these permissions here:

String [] permissions = { Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION };

And when requesting:

public void requestPermissions(int requestCode)
{
PermissionHelper.requestPermissions(this, requestCode, permissions);
}

OR

if(hasPermisssion())
{
PluginResult r = new PluginResult(PluginResult.Status.OK);
context.sendPluginResult(r);
return true;
}
else {
PermissionHelper.requestPermissions(this, 0, permissions);
}

However, the issue with coarse only not working is probably due to the fact that it appears that if any of the requested permissions are denied, then we treat the entire prompt as a denial:

public void onRequestPermissionResult(int requestCode, String[] permissions,
int[] grantResults) throws JSONException
{
PluginResult result;
//This is important if we're using Cordova without using Cordova, but we have the geolocation plugin installed
if(context != null) {
for (int r : grantResults) {
if (r == PackageManager.PERMISSION_DENIED) {
LOG.d(TAG, "Permission Denied!");
result = new PluginResult(PluginResult.Status.ILLEGAL_ACCESS_EXCEPTION);
context.sendPluginResult(result);
return;
}
}
result = new PluginResult(PluginResult.Status.OK);
context.sendPluginResult(result);
}
}

This is obviously problematic. I think it should only throw an error if highAccuracy was requested, but FINE location is not granted.

@breautek breautek added the bug label Sep 20, 2021
@bhandaribhumin
Copy link
Author

bhandaribhumin commented Sep 21, 2021

@breautek Thanks for the observation I already try to debugging the code but ACCESS_COARSE_LOCATION failed all the time. Found valid issue on beta and it is not fixed yet. Here is the issue link google-issuetracker.

@jcesarmobile
Copy link
Member

I think the plugin behavior should be changed to consider that the permission has been granted if on Android 12 and only coarse permission was granted, or at least if highAccuracy is false.

But sadly there is a bug on the WebView that still won't get location in some cases even if we consider it as granted
https://bugs.chromium.org/p/chromium/issues/detail?id=1269362

@dpa99c
Copy link
Contributor

dpa99c commented Oct 18, 2022

This is now resolved by merging of PR #250

@dpa99c dpa99c closed this as completed Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants