Skip to content

Geolocation on Android #1967

Closed
Closed

Description

@pkar70

Current behavior

RequestAccessAsync() returns GeolocationAccessStatus.Allowed, but trying to use Geolocation throws exception (no permission) - but in Manifest, permission is correct (ACCESS_FINE_LOCATION)

Expected behavior

No exception.

I tried to dig into problem, and found this info
But I never do any program for Android environment directly (only using Uno), so it would be hard for me adding appropriate code.

How to reproduce it (as minimally and precisely as possible)

Environment

Nuget Package: 2.0.512.3599

Package Version(s):

Affected platform(s):

  • iOS
  • Android
  • WebAssembly
  • WebAssembly renderers for Xamarin.Forms
  • Windows
  • Build tasks
  • Solution Templates

Visual Studio:

  • 2017 (version: )
  • 2019 (version: )
  • for Mac (version: )

Relevant plugins:

  • Resharper (version: )

Anything else we need to know?

Activity

  1. added
    kind/bug
    triage/untriaged
    on Oct 26, 2019
  2. added
    platform/android 🤖
    and removed
    triage/untriaged
    on Oct 26, 2019
  3. jeromelaban commented on Oct 28, 2019

    @jeromelaban
    Member

    You may need an additional permission in the application, such as ACCESS_COARSE_LOCATION.

  4. pkar70 commented on Oct 28, 2019

    @pkar70
    ContributorAuthor

    Both (FINE and COARSE) has attribute "Protection level: dangerous" (see https://developer.android.com/reference/android/Manifest.permission.html#ACCESS_COARSE_LOCATION). And digging internet for solution I found that COARSE is 'included' in FINE, so it is unnecessary to add COARSE if someone declares FINE.

    Android Developers
  5. jeromelaban commented on Oct 28, 2019

    @jeromelaban
    Member

    Which version of Android are you testing on?

  6. pkar70 commented on Oct 28, 2019

    @pkar70
    ContributorAuthor

    Android 8.1 Go.

  7. jeromelaban commented on Oct 28, 2019

    @jeromelaban
    Member

    In such case, it may be related to system permissions. Check that the application was given access in the devices settings.

  8. pkar70 commented on Oct 28, 2019

    @pkar70
    ContributorAuthor

    Yes, it is permission problem. Permission CAN be enabled manually in system Settings, but RequestAsync() on Windows displays dialog asking for permission, and return granted/denied. On Android/Uno, RequestAsync() should be functional equivalent - ask for permission, i.e. it should call ActivityCompat.requestPermissions (from sample above). But my knowledge of Android is very, very limited, so I don't want to try to implement this code myself.
    Besides, I downloaded newer Uno clone, and probably something meshed up, as it doesn't want to compile :(
    And I didn't have enough time to deal with this for last days.

  9. pkar70 commented on Oct 29, 2019

    @pkar70
    ContributorAuthor

    I started to implement this... and even found great helper function in Uno (in files src\Uno.UWP\Extensions\PermissionsHelper.cs and src\Uno.UI\Extensions\PermissionsHelper.Android.cs) ... But I don't know how to properly use CancelationToken, so I should debug it first (before PR):

    public static async Task<GeolocationAccessStatus> RequestAccessAsync()
    {
    	// below 6.0 (API 23), permission are granted
    	if (Android.OS.Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.M)
    	{
    		return GeolocationAccessStatus.Allowed;
    	}
    
    	CancellationTokenSource cts = new CancellationTokenSource();
    
    	if(await Windows.Extensions.PermissionsHelper.CheckFineLocationPermission(cts.Token))
    	{
    			return GeolocationAccessStatus.Allowed;
    	}
    
    	return GeolocationAccessStatus.Denied;
    
    }
    

    EDIT: this works only if permission is granted (using system Settings). If permission is not granted, no dialog (asking user for permission) is presented, and app seems to stop working.

  10. added this to the HighPriority milestone on Sep 1, 2020
  11. removed this from the HotFixes milestone on Sep 2, 2020
  12. juliecantin commented on Sep 3, 2020

    @juliecantin
    Contributor

    @pkar70 I believe this issue is now resolved, thanks to some fixes in Uno. Could you confirm on your end that you are able to use Geolocator with the latest version of Uno on Android?

  13. pkar70 commented on Sep 3, 2020

    @pkar70
    ContributorAuthor

    Yes, changes in permissionhelper allows to correctly implement RequestAccessAsync, and #3891 make better Geopoint.
    Although #2536 have more functionality than current Uno implementation, I think this Issue can be closed.

  14. added
    project/non-ui ⚙️
    on Sep 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugplatform/android 🤖project/non-ui ⚙️

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions