Handle permissions in Xamarin.Forms

Alegria Kilanda
Jun 27, 2020

--

In this article, I present a way to handle permissions using Xamrin.Form.

Xamrin.Form

First let’s create an enum named EPermission. These are the permissions used in the project.

Now let’s create an interface named IPermissionDependency

Xamarin.Android

In Android, let’s create a class named PermissionDependency.cs

Inside the class PermissionDependency it was defined:

Delegate OnExecuteResponseRequestPermission: It is invoked in MainActivity, when user answer.

Delegate OnPermissionRequest: It is invoked in PermissionDependency after invoking OnExecuteResponseRequestPermission.

GetManifestPermission: Returns permission based on Enum EPermission.

CheckPermission: Method used to check the existence of permission.

RequestPermission: Invokes the RequestPermission dialog.

MainActivity

Xamarin.iOS

On iOS we have nothing to do.

After that done we just need to invoke these functions in xamarin.Forms. Let’s create a class for support named Permission.

MainPage.Xaml

MainPage.cs (bihand)

The project is available on github for contributions and improvements.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response