Reputation: 2286
I can't find a solution to this issue anywhere, On android, Requesting permissions Does not function I use James Montemagno's PermissionsPlugin Example:
await Application.Current?.MainPage?.DisplayAlert("Need location", "Gunna need that location", "OK");
and also I always have location permissions set to granted no matter what, but when I switch off my locations on my device : Galaxy s4 with Kitkat. I get the permission request task canceled all the time, I don't know what to do, anyone please help.
var resultrs = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Location });
Upvotes: 0
Views: 1821
Reputation: 33
The error you are getting is not related to Permission you do not need to ask for permission from user below Marshmallow Api which is your case. Since you are testing on kiKat. You can use Geolocator Class of Xamarin.Essential and detect whether the Gps is Active/Not If it is not send user to mobile settings page or prompt user that enable your Gps before continue.
Upvotes: 1
Reputation: 33
Make target platform from automatic API 25 to override API 25 for your xamarin android project.
Upvotes: 0
Reputation: 526
add the following to your AssemblyInfo.cs file in your Android project:
[assembly: UsesFeature("android.hardware.location", Required = false or true)]
[assembly: UsesFeature("android.hardware.location.gps", Required = false or true)]
[assembly: UsesFeature("android.hardware.location.network", Required = false or true)]
and put OnRequestPermissionsResult in MainActivity.cs
[Activity(Label = "JobTimer.Android", Theme = "@style/MyTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
this.Window.AddFlags(WindowManagerFlags.Fullscreen);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
{
PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
Upvotes: 0