4

Is there a way I can do that with a Plugin or do I need to write some kind of a custom renderer?

deczaloth
  • 7,094
  • 4
  • 24
  • 59
Alan2
  • 23,493
  • 79
  • 256
  • 450
  • Does this answer your question? [How to know the current OS / platform of the executing code (Android / iOS)](https://stackoverflow.com/questions/18570878/how-to-know-the-current-os-platform-of-the-executing-code-android-ios) – grooveplex Jan 12 '20 at 15:48

2 Answers2

10

use Xamarin.Essentials

// Operating System Version Number (7.0)
var version = DeviceInfo.VersionString;

// Platform (Android)
var platform = DeviceInfo.Platform;
Jason
  • 86,222
  • 15
  • 131
  • 146
  • 3
    If someone wants to compare versions this could be used `if (DeviceInfo.Version.Major >= 11) { // .... }` – testing Aug 27 '20 at 11:56
  • Official docs link : https://learn.microsoft.com/en-us/xamarin/essentials/device-information?tabs=ios – Mac Jan 22 '21 at 10:05
2

You could use Xam.Plugin.DeviceInfo as well.

Xam.Plugin.DeviceInfo: https://www.nuget.org/packages/Xam.Plugin.DeviceInfo

Code: In App.cs

// The root page of your application
        MainPage = new ContentPage
        {
            Content = new StackLayout
            {
                Padding = 50,
                VerticalOptions = LayoutOptions.Center,
                Children = {
                      new Label{ Text = "Id: " + CrossDeviceInfo.Current.Id},
                      new Label{ Text = "Model: " + CrossDeviceInfo.Current.Model},
                      new Label{ Text = "Platform: " + CrossDeviceInfo.Current.Platform},
                      new Label{ Text = "Version: " + CrossDeviceInfo.Current.Version},
                }
            }
        };

enter image description here

You could download the source code form the link for reference. https://github.com/jamesmontemagno/DeviceInfoPlugin

Wendy Zang - MSFT
  • 10,509
  • 1
  • 7
  • 17