Skip to content

Instantly share code, notes, and snippets.

@DamianSuess
Last active January 28, 2022 22:02
Show Gist options
  • Save DamianSuess/2de13c876835dbc8a892c6dbc6224d0f to your computer and use it in GitHub Desktop.
Save DamianSuess/2de13c876835dbc8a892c6dbc6224d0f to your computer and use it in GitHub Desktop.
Get Android's SIM ICC Id and device's IMEI number
// Requires the following permission in your AndroidManifest.xml
// <uses-permission android:name="android.permission.READ_PHONE_STATE" />
using System.Collections.Generic;
using Android.Telephony;
// ...
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SubscriptionManager sm = Android.Telephony.SubscriptionManager.From(Android.App.Application.Context);
IList<SubscriptionInfo> sis = sm.ActiveSubscriptionInfoList;
SubscriptionInfo si = sis[0];
string carrier = si.CarrierName;
string iccId = si.IccId;
string phoneNum = si.Number;
System.Diagnostics.Debug.WriteLine("Carrier: " + carrier);
System.Diagnostics.Debug.WriteLine("SIM Card IccId: " + iccId);
System.Diagnostics.Debug.WriteLine("Phone Number: " + phoneNum);
// Bonus, Get the Device Id (aka, IMEI Id)
TelephonyManager tm = (TelephonyManager)GetSystemService(Android.Content.Context.TelephonyService);
string deviceId = tm.DeviceId;
System.Diagnostics.Debug.WriteLine("Device Id: " + deviceId);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment