Created
October 31, 2018 13:22
-
-
Save juucustodio/0f2703e15da942adc33aa5de2e36fbb3 to your computer and use it in GitHub Desktop.
Example how your Xamarin.Forms application get the IMEI code from device - http://julianocustodio.com/imei
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Plugin.Permissions; | |
using Plugin.Permissions.Abstractions; | |
using Xamarin.Forms; | |
namespace DemoImei | |
{ | |
public partial class MainPage : ContentPage | |
{ | |
public MainPage() | |
{ | |
InitializeComponent(); | |
} | |
private async void Button_OnClicked(object sender, EventArgs e) | |
{ | |
//Verify Permission | |
var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Phone); | |
if (status != PermissionStatus.Granted) | |
{ | |
var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Phone); | |
//Best practice to always check that the key exists | |
if (results.ContainsKey(Permission.Phone)) | |
status = results[Permission.Phone]; | |
} | |
//Get Imei | |
LblImei.Text = "IMEI = " + DependencyService.Get<IServiceImei>().GetImei(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment