Reputation: 1217
I'm using Xamarin Android and I want to trigger an event whenever the location access is changed by a user. When the app starts it prompts for permission to access location service, I want to trigger some event when a user selects yes or no. Are there any such events in Android that can handle it?
Upvotes: 0
Views: 269
Reputation: 2789
You can use PermissionChecker
class's CheckSelfPermission(string permission)
method which was introduced in API 23.0
Eg code:
const string permission = Manifest.Permission.AccessFineLocation; //Also you can use ACCESS_COARSE_LOCATION
if (CheckSelfPermission(permission) == (int)Permission.Granted)
{
//Operation if permission is granted
}
else
{
//Operation if permission is not granted
}
Further reading https://blog.xamarin.com/requesting-runtime-permissions-in-android-marshmallow/
Upvotes: 1