Informações do Dispositivo – Xamarin.Forms

Olá, neste post irei demonstrar como obter algumas informações do dispositivo em suas aplicações Xamarin.Forms.

 

Informações que podem ser obtidas

  • Nome do dispositivo
  • Id
  • Fabricante
  • Modelo
  • Sistema Operacional
  • Versão do Sistema Operacional

 

ADICIONANDO O NUGET PACKAGE

Clique com o botão direito em cima de sua Solution e selecione “Manage NuGet Packages for Solution…”.

1

 

Digite “Xam.Plugin.DeviceInfo” e selecione o plugin como demonstrado na imagem a seguir.

2

 

Selecione todos os projetos e clique no botão “Install”.

2

 

 

C#

Referencie o plugin DeviceInfo e utilize “CrossDeviceInfo.Current” seguido da propriedade desejada, como demonstrado a seguir.


using Plugin.DeviceInfo;
using Xamarin.Forms;
namespace DemoDeviceInfo
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
DeviceName.Text = "DeviceName: " + CrossDeviceInfo.Current.DeviceName;
Id.Text = "Id: " + CrossDeviceInfo.Current.Id;
Manufacturer.Text = "Manufacturer: " + CrossDeviceInfo.Current.Manufacturer;
Model.Text = "Model: " + CrossDeviceInfo.Current.Model;
Version.Text = "Version: " + CrossDeviceInfo.Current.Version;
Platform.Text = "Platform: " + CrossDeviceInfo.Current.Platform.ToString();
}
}
}

 

 

XAML


<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms&quot;
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml&quot;
xmlns:local="clr-namespace:DemoDeviceInfo"
x:Class="DemoDeviceInfo.MainPage">
<StackLayout HorizontalOptions="Center" VerticalOptions="Center">
<Label x:Name="DeviceName" />
<Label x:Name="Id" />
<Label x:Name="Manufacturer" />
<Label x:Name="Model" />
<Label x:Name="Platform" />
<Label x:Name="Version" />
</StackLayout>
</ContentPage>

view raw

MainPage.xaml

hosted with ❤ by GitHub

 

 

Resultado

Screenshot_20180409-134109

 

Esse e todos os exemplos deste blog encontram-se disponíveis no GitHub.

icongithub

Um comentário em “Informações do Dispositivo – Xamarin.Forms

Deixe um comentário