After Android 6.0, we have to using Runtime Persmissions. No more enaugth to create an Android.Manifest file. How can we correctly use it?
Step 1: Android.Manifest file
Still we have to create an Android.Manifest file, but a little bit otherwise. We have to use this way: https://developer.android.com/training/permissions/requesting#java. So, if we have used it so far as “uses-permission” before, from now we have to use it as “uses-permisson-sdk-<SDK_Version_Number>”. We can specify the max SDK version too.
<uses-permission-sdk-23 android:maxSdkVersion="28" android:name="android.permission.ACCESS_FINE_LOCATION" />
We have to specify the minimum SDK version of the application (https://developer.android.com/guide/topics/manifest/uses-sdk-element), because, if we don’t do, the minimum SDK version will be the 1.0. We can define the target and the max SDK version as well.
<uses-sdk android:minSdkVersion="23" />
Example Android.Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.companyname" android:versionCode="1" android:versionName="1.0.15" android:installLocation="auto">
<uses-sdk android:minSdkVersion="23" />
<uses-permission-sdk-23 android:maxSdkVersion="28" android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission-sdk-23 android:maxSdkVersion="28" android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission-sdk-23 android:maxSdkVersion="28" android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission-sdk-23 android:maxSdkVersion="28" android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission-sdk-23 android:maxSdkVersion="28" android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission-sdk-23 android:maxSdkVersion="28" android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission-sdk-23 android:maxSdkVersion="28" android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission-sdk-23 android:maxSdkVersion="28" android:name="android.permission.INTERNET" />
<uses-permission-sdk-23 android:maxSdkVersion="28" android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission-sdk-23 android:maxSdkVersion="28" android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission-sdk-23 android:maxSdkVersion="28" android:name="android.permission.RECEIVE_SMS" />
<uses-permission-sdk-23 android:maxSdkVersion="28" android:name="android.permission.SEND_SMS" />
<uses-permission-sdk-23 android:maxSdkVersion="28" android:name="android.permission.WRITE_SMS" />
<uses-permission-sdk-23 android:maxSdkVersion="28" android:name="android.permission.READ_SMS" />
<application android:label="Application" android:icon="@drawable/icon">
</application>
</manifest>
Step 2: Runtime Permission
Open the MainActivity.cs file in the Android Project. We have to create a Request to the user: “hello we have to use the calendar, location, sms, etc. when this app running”. The user will deside that, he/she will use these or not.
var requiredPermissions = new string[]
{
Manifest.Permission.AccessFineLocation,
Manifest.Permission.AccessCoarseLocation,
Manifest.Permission.AccessNetworkState,
Manifest.Permission.AccessLocationExtraCommands,
Manifest.Permission.AccessMockLocation,
Manifest.Permission.AccessNetworkState,
Manifest.Permission.AccessWifiState,
Manifest.Permission.Internet,
Manifest.Permission.WriteExternalStorage,
Manifest.Permission.ReadExternalStorage,
Manifest.Permission.ReceiveSms,
Manifest.Permission.SendSms,
Manifest.Permission.WriteSms,
Manifest.Permission.ReadSms
};
RequestPermissions(requiredPermissions, 1);
What have we done? We said that these permissions are neccessary to use at runtime and we created the request to the user. If any of theese permissions is not granted, it will be asked at the start of the application. If all were granted, nothing will happen. Okay, but what is “1” (the second param of the Request)? This is the request code, this can be another too, this is an app-defined code.
If we are corious, that our request is granted or not, we can override the OnRequestPermissionsResult() function.
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
This function will response our permission request(s) result(granted or not).
I’m excited to uncover this page. I need to to thank you for ones time for this particularly fantastic read !! I definitely really liked every part of it and i also have you saved to fav to look at new information in your site.
I was reading through some of your posts on this site and I think this website is real informative! Continue putting up.Thanks!
Say, you got a nice blog post.Thanks Again. Awesome.
I’m also an expert in this topic therefore I can understand your hard work.Thanks!
Awesome blog article.Really looking forward to read more. Awesome.
This is one awesome article. Great.
Muchos Gracias for your article post.Really looking forward to read more. Will read on…
Im obliged for the blog article.Really thank you! Fantastic.
wow, awesome post.Much thanks again. Cool.
Enjoyed every bit of your blog post.Really looking forward to read more. Fantastic.
A big thank you for your post.Really looking forward to read more. Really Great.
Great, thanks for sharing this blog post.Really thank you! Awesome.
Thanks for sharing, this is a fantastic blog. Keep writing.
A round of applause for your blog. Really Cool.
wow, awesome blog article.Really thank you! Great.
Thanks for the blog post.Really thank you! Great.
Thanks for the blog.Much thanks again.
I really liked your blog article.Really looking forward to read more. Keep writing.
I really enjoy the article post.Much thanks again. Really Cool.
I value the blog post.Really thank you! Want more.
Very neat article.Much thanks again. Awesome.
Excellent post however , I was wondering if you could write a litte more on this subject? I’d be very grateful if you could elaborate a little bit more. Cheers!
Great blog article.Really thank you! Keep writing.
I truly appreciate this post.Really thank you! Keep writing.
Awesome blog post. Much obliged.
I cannot thank you enough for the blog post.Thanks Again. Want more.
Hey, thanks for the blog article. Want more.
Awesome blog. Fantastic.
Wow, great blog.Much thanks again. Fantastic.
Looking forward to reading more. Great blog article. Great.
Really enjoyed this blog article.Thanks Again. Keep writing.
Great blog post.Thanks Again. Awesome.
Say, you got a nice blog.Much thanks again. Really Great.
Hey, thanks for the article post.Really looking forward to read more. Really Cool.
Looking forward to reading more. Great article post.Much thanks again. Great.
Thanks again for the article post.Really looking forward to read more. Want more.
Really appreciate you sharing this article post.Thanks Again. Keep writing.
I would be great if you could point me in the direction of a good platform.
I think this is a real great blog article.Really thank you! Awesome.
Very good blog.Thanks Again. Keep writing.
Thanks designed for sharing such a pleasant idea, post is fastidious, thats why i have read it fully
Great, thanks for sharing this blog article. Will read on…