Android access to mobile SIM card operator information

  • 2020-06-07 05:15:47
  • OfStack

This paper describes the Android method to obtain the operator information of SIM card, which is of great practical value for Android programming. To share with you for your reference. The specific methods are as follows:

The main function codes are as follows:


/**
 *  To obtain SIM Card operators 
 * 
 * @param context
 * @return
 */
public static String getOperators(Context context) {
 TelephonyManager tm = (TelephonyManager) context
  .getSystemService(Context.TELEPHONY_SERVICE);
 String operator = null;
 String IMSI = tm.getSubscriberId();
 if (IMSI == null || IMSI.equals("")) {
 return operator;
 }
 if (IMSI.startsWith("46000") || IMSI.startsWith("46002")) {
 operator = " China Mobile ";
 } else if (IMSI.startsWith("46001")) {
 operator = " China Unicom ";
 } else if (IMSI.startsWith("46003")) {
 operator = " China Telecom ";
 }
 return operator;
}

/**
 *  Mobile phone models 
 * 
 * @return
 */
public static String getPhoneModel() {
 return android.os.Build.MODEL;
}

/**
 *  System version 
 * 
 * @return
 */
public static String getSystemVersion() {
 return android.os.Build.VERSION.RELEASE;
}

The permission code is as follows:


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

Hopefully, this article has helped you with your Android programming


Related articles: