xamarin / Essentials

Xamarin.Essentials is no longer supported. Migrate your apps to .NET MAUI, which includes Maui.Essentials.
https://aka.ms/xamarin-upgrade
Other
1.52k stars 505 forks source link

[Enhancement] Ability to request user to turn on location services #1058

Open dsdilpreet opened 4 years ago

dsdilpreet commented 4 years ago

Summary

I was trying out new Permissions API introduced in version 1.4. I was wondering if it is possible to add a feature in there that could ask permissions from user to turn on location services programmatically on user's phone.

API Changes

It could look something like this.

Request Permissions

Permissions.RequestAsync<Permissions.LocationServicesEnable>()

Check Status

Permissions.CheckStatusAsync<Permissions.LocationServicesEnabled>()

Intended Use Case

This addition can be used for requesting permissions from user to turn the location services on. It would be ideal, in my opinion, to use with newly introduced API changes for requesting and checking status of location permissions for application.

Redth commented 4 years ago

Can you add some more information on what API's this might use on each platform?

dsdilpreet commented 4 years ago

Hi @Redth ,

I did some more research, I think one way to do it is to open the device settings page for location services.

On Android,

            var intent = new Intent(Android.Provider.Settings.ActionLocationSourceSettings);
            intent.AddFlags(ActivityFlags.NewTask);
            Android.App.Application.Context.StartActivity(intent);

On iOS, It seems that iOS does not allow you to do that post iOS 11 https://stackoverflow.com/questions/52301580/how-to-programmatically-open-settings-privacy-location-services-in-ios-11

I am not sure if there is any better way to do it like a dialog box similar to location permission which could automatically enable location services under the hood if user responds OK to it.

Just wanted to discuss and bring it out there and see if its possible.

minaairsupport commented 4 years ago

yea I was about to ask the same request we need checking permissions & requesting them to be exposed
https://github.com/xamarin/Essentials/tree/master/Xamarin.Essentials/Permissions

Xamarin.Essentials.Permissions.CheckStatusAsync for checking all permissions Xamarin.Essentials.Permissions. RequestAsync for requestion a permission Xamarin.Essentials.Permissions.CheckPermissionStatusAsync for checking specific permission

dsdilpreet commented 4 years ago

Seems like there is SettingsClient API on Android to enable location services on device. https://developers.google.com/android/reference/com/google/android/gms/location/SettingsClient.html

But iOS does not seem to have such API at this point.

jamesmontemagno commented 4 years ago

Turning on and off device services isn't an API that will be consistent across devices. We have an API to open the app settings in AppInfo.

A new API in DeviceInfo could mimic this API to attempt to open specific device settings. I am not sure though if really we could provide a consistent experience, but worth an attempt.

jrahma commented 3 years ago

Turning on and off device services isn't an API that will be consistent across devices. We have an API to open the app settings in AppInfo.

A new API in DeviceInfo could mimic this API to attempt to open specific device settings. I am not sure though if really we could provide a consistent experience, but worth an attempt.

I hope there will be a way to Cancel the permission using the Permission package without having to go to Settings so we can see a switch for example to enable or disable a permission.