get phone Subscriber Id - Android android.telephony

Android examples for android.telephony:TelephonyManager

Description

get phone Subscriber Id

Demo Code

import android.content.Context;
import android.telephony.TelephonyManager;

public class Main {

  public static String getIMSI(Context context) {

    if (null == context) {
      return null;
    }/*  w  w  w.  java 2 s .  c  om*/
    String imsi = null;
    try {
      TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
      imsi = tm.getSubscriberId();
    } catch (Exception e) {
    }
    return imsi;
  }

}

Related Tutorials