Android开发之获取SIM卡信息和手机号码
生活随笔
收集整理的這篇文章主要介紹了
Android开发之获取SIM卡信息和手机号码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
獲取SIM卡信息和手機號碼的工具類,記錄一下方便以后使用
import android.content.Context;
import android.telephony.TelephonyManager;/*** Created by WangJinyong on 2018/3/31.* 獲取SIM卡信息和手機號碼*/public class PhoneInfoUtils {private static String TAG = "PhoneInfoUtils";private TelephonyManager telephonyManager;//移動運營商編號private String NetworkOperator;private Context context;public PhoneInfoUtils(Context context) {this.context = context;telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);}//獲取sim卡iccidpublic String getIccid() {String iccid = "N/A";iccid = telephonyManager.getSimSerialNumber();return iccid;}//獲取電話號碼public String getNativePhoneNumber() {String nativePhoneNumber = "N/A";nativePhoneNumber = telephonyManager.getLine1Number();return nativePhoneNumber;}//獲取手機服務商信息public String getProvidersName() {String providersName = "N/A";NetworkOperator = telephonyManager.getNetworkOperator();//IMSI號前面3位460是國家,緊接著后面2位00 02是中國移動,01是中國聯通,03是中國電信。
// Flog.d(TAG,"NetworkOperator=" + NetworkOperator);if (NetworkOperator.equals("46000") || NetworkOperator.equals("46002")) {providersName = "中國移動";//中國移動} else if (NetworkOperator.equals("46001")) {providersName = "中國聯通";//中國聯通} else if (NetworkOperator.equals("46003")) {providersName = "中國電信";//中國電信}return providersName;}public String getPhoneInfo() {TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);StringBuffer sb = new StringBuffer();sb.append("\nLine1Number = " + tm.getLine1Number());sb.append("\nNetworkOperator = " + tm.getNetworkOperator());//移動運營商編號sb.append("\nNetworkOperatorName = " + tm.getNetworkOperatorName());//移動運營商名稱sb.append("\nSimCountryIso = " + tm.getSimCountryIso());sb.append("\nSimOperator = " + tm.getSimOperator());sb.append("\nSimOperatorName = " + tm.getSimOperatorName());sb.append("\nSimSerialNumber = " + tm.getSimSerialNumber());sb.append("\nSubscriberId(IMSI) = " + tm.getSubscriberId());return sb.toString();}
}
總結
以上是生活随笔為你收集整理的Android开发之获取SIM卡信息和手机号码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【APPInventor\腾讯云】使用A
- 下一篇: python3 获取商店里App评论+