Skip to content

Instantly share code, notes, and snippets.

@arman-hpp
Created March 31, 2019 03:46
Show Gist options
  • Save arman-hpp/d08aecbb0b7383d121620d3f58989ea5 to your computer and use it in GitHub Desktop.
Save arman-hpp/d08aecbb0b7383d121620d3f58989ea5 to your computer and use it in GitHub Desktop.
private string GetImei()
{
var permissionCheck = ContextCompat.CheckSelfPermission(this, Manifest.Permission.ReadPhoneState);
if (permissionCheck == Permission.Denied)
{
ActivityCompat.RequestPermissions(this, new[] { Manifest.Permission.ReadPhoneState }, 0);
}
var mTelephonyMgr = (TelephonyManager)GetSystemService(TelephonyService);
if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
return mTelephonyMgr.GetImei(0); // Some phones has more than 1 SIM card or may not have a SIM card inserted at all
#pragma warning disable CS0618 // Type or member is obsolete
return mTelephonyMgr.DeviceId;
#pragma warning restore CS0618 // Type or member is obsolete
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment