Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

What is the easiest way to know which API method was introduced in which API level?

$
0
0

I found this link that nicely describes everything about these Android versions and how they work with Xamairn. In the document it says:

"If you select a Minimum Android version that is lower than your Target Framework setting, some APIs may not be available to your app at runtime. However, your app can still run on an earlier device, but with reduced functionality. For each API that is not available on Android platforms corresponding to your Minimum Android version setting, your code must explicitly check the value of the Android.OS.Build.VERSION.SdkInt property to determine the API level of the platform the app is running on.

For example, let's suppose that we want to use the NotificationBuilder.SetCategory method to categorize a notification when running on Android 5.0 Lollipop (and later), but we still want our app to run on earlier versions of Android such as Android 4.1 Jelly Bean (where SetCategory is not available). Referring to the Android version table at the beginning of this guide, we see that the build version code for Android 5.0 Lollipop is Android.OS.BuildVersionCodes.Lollipop. To support older versions of Android where SetCategory is not available, our code can detect the API level at runtime and conditionally call SetCategory only when the API level is greater than or equal to the Lollipop build version code:

if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
{
builder.SetCategory(Notification.CategoryEmail);
}
"
This is a huge issue because if the developer forgets to put the check the application will not run properly on earlier platforms. So I tried this myself, so I set the Target Framework to 5.0 and the Minimum Android version to 4.1 to see if I get a warning that indicates that this method is only available on Android 5.0 and higher but unfortunately, I didn’t get any warning. I'm using Visual Studio 2017 Enterpise edition.

So my question is do the developers have to know by heart what API method was introduced in what API level and put the check? Doesn't that make the development significantly difficult?


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>