Hi All
I am using Geolocator Plugin as well as Permissions Plugin from James Montemagno.
The issue i am facing is that on Android it is not prompting a user for permission to get Location, on iOS it works fine. Below is code extracts:
try
{
var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);
if (status != PermissionStatus.Granted)
{
if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location))
{
await DisplayAlert("Need location", "Gunna need that location", "OK");
}
var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Location });
status = results[Permission.Location];
}
if (status == PermissionStatus.Granted)
{
var results = await CrossGeolocator.Current.GetPositionAsync(TimeSpan.FromMilliseconds(10000));
latLable.Text = results.Latitude.ToString();
lonLable.Text = results.Longitude.ToString();
}
else if (status != PermissionStatus.Unknown)
{
await DisplayAlert("Location Denied", "Can not continue, try again.", "OK");
}
}
catch (Exception ex)
{
await DisplayAlert("Error", ex.Message,"OK");
}
I have also added the below to my Main activity:
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
{
PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
I have also added the below permissions to AndroidManifest:
uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"
I am targeting Android 7.1
Currently I have to go into my phones Setting>App>MyApp and manually set the permissions.
I have read many forums and my implementation looks correct.
One Forum suggested i should target Android 6, but i am struggling to retarget my Packages when I do this.