476rick 476rick - 1 month ago 24
C# Question

Xamarin Forms request internet permission Android 6 from PCL

I'm building a cross-platform application with Xamarin.Forms.
For the content I use an async call to a API which returns JSON.
So I need the INTERNET permission.

Example of the code that contacts the API:

var data = await wc.GetStringAsync("http://website.for.content/content-api/Category/?format=json");


This line is in the Android Manifest:

<uses-permission android:name="android.permission.INTERNET" />


All the code I wrote for the application is in a portable class library. So I don't have any platform specific code (yet).

How do I check and request internet permission from the portable class library?

Answer

There are Normal and Dangerous permissions, Internet access is a normal permission and thus only needs to be defined in the application's manifest for installation purposes and is auto-granted at runtime.

Normal permissions cover areas where your app needs to access data or resources outside the app's sandbox, but where there's very little risk to the user's privacy or the operation of other apps. For example, permission to set the time zone is a normal permission. If an app declares that it needs a normal permission, the system automatically grants the permission to the app

Ref: https://developer.android.com/guide/topics/security/normal-permissions.html

Comments