How can I get the ICCID number of my phone?

How can I get the ICCID number of my phone?

I looked in the TelephonyManager class but didn't find a way to get the ICCID number, there is only a method that tells if the ICC card is present.

+4


source to share


3 answers


I believe I will get iccid. getSimSerialNumber()



For Android 5.1+, see this answer to this question for which I deserve zero points.

+11


source


UPDATE for Android 5.1 (Credit to Erick M Sprengel )

Added "Multiple SIM support" for Android 5.1 (API 22). Instead of using, getSimSerialNumber

you can use . SubscriptionManager

SubscriptionManager sm = SubscriptionManager.from(mContext);

// it returns a list with a SubscriptionInfo instance for each simcard
// there is other methods to retrieve SubscriptionInfos (see [2])
List<SubscriptionInfo> sis = sm.getActiveSubscriptionInfoList();

// getting first SubscriptionInfo
SubscriptionInfo si = sis.get(0);

// getting iccId
String iccId = si.getIccId();

      



You will need a permit: ( Damian's loan )

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

      

+4


source


@Jakar, thanks a lot! Here's the same code in C # using Xamarin / Mono.Android

Requires permission set in your AndroidManifest.xml

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

      

Simple C #

using System.Collections.Generic;
using Android.Telephony;
// ...
protected override void OnCreate(Bundle bundle)
{
  base.OnCreate(bundle);

  // Requires, android.permission.READ_PHONE_STATE
  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 IMEI Id (aka, DeviceId)
  TelephonyManager tm = (TelephonyManager)GetSystemService(Android.Content.Context.TelephonyService);
  string deviceId = tm.DeviceId;

  System.Diagnostics.Debug.WriteLine("Device Id: " + deviceId);
}

      

Both SubscriptionManager and SubscriptionInfo are in the Android.Telephony namespace

In truth, this example was needed to activate my phone on the fly and without the ability to use the SIM card tool. And my eyes are not what they use. Have a look at DroidTelephonySimInfo.cs at gist.github.com

+1


source







All Articles