获取SIM卡各类信息 系统工具类

 
package com.lx.utils;

import java.util.List;
import java.util.Locale;

import android.app.Activity;
import android.content.Context;
import android.telephony.CellLocation;
import android.telephony.NeighboringCellInfo;
import android.telephony.TelephonyManager;

/**
 * 系统工具类 Created by xwc on 2018-06-04.
 */
public class SystemUtil {

    /**
     * 获取当前手机系统语言。
     * 
     * @return 返回当前系统语言。例如:当前设置的是“中文-中国”,则返回“zh-CN”
     */
    public static String getSystemLanguage() {
        return Locale.getDefault().getLanguage();
    }

    /**
     * 获取当前系统上的语言列表(Locale列表)
     * 
     * @return 语言列表
     */
    public static Locale[] getSystemLanguageList() {
        return Locale.getAvailableLocales();
    }

    /**
     * 获取当前手机系统版本号
     * 
     * @return 系统版本号
     */
    public static String getSystemVersion() {
        return android.os.Build.VERSION.RELEASE;
    }

    /**
     * 获取手机型号
     * 
     * @return 手机型号
     */
    public static String getSystemModel() {
        return android.os.Build.MODEL;
    }

    /**
     * 获取手机厂商
     * 
     * @return 手机厂商
     */
    public static String getDeviceBrand() {
        return android.os.Build.BRAND;
    }

    /**
     * 获取手机IMEI(需要“android.permission.READ_PHONE_STATE”权限)
     * 
     * @return 手机IMEI
     */
    public static String getIMEI(Context ctx) {
        TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Activity.TELEPHONY_SERVICE);
        if (tm != null) {

            return tm.getDeviceId();

        }
        return null;
    }

    /**
     * 获取手机ICCID(需要“android.permission.READ_PHONE_STATE”权限)
     * 
     * @return 手机IMEI
     */
    public static String getICCID(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
        if (tm != null) {

            return tm.getSimSerialNumber();

        }
        return null;
    }

    /**
     * 获取手机号(需要“android.permission.READ_PHONE_STATE”权限)
     * 
     * @return 手机号
     */
    public static String getLine1Number(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
        if (tm != null) {

            return tm.getLine1Number();

        }
        return null;
    }

    /**
     * 电话状态: 1.tm.CALL_STATE_IDLE=0 无活动 2.tm.CALL_STATE_RINGING=1 响铃 3.tm.CALL_STATE_OFFHOOK=2 摘机
     * 
     * @return 电话状态
     */
    public static Integer getCallState(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
        if (tm != null) {

            return tm.getCallState();

        }
        return null;
    }

    /**
     * 电话方位:
     * 
     * @return 电话方位
     */
    public static CellLocation getCellLocation(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
        if (tm != null) {

            return tm.getCellLocation();

        }
        return null;
    }

    /**
     * 设备的软件版本号: 例如:the IMEI/SV(software version) for GSM phones. Return null if the software version is not available.
     * 
     * @return 软件版本号
     */
    public static String getDeviceSoftwareVersion(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
        if (tm != null) {

            return tm.getDeviceSoftwareVersion();

        }
        return null;
    }

    /**
     * 附近的电话的信息: 类型:List<NeighboringCellInfo> 需要权限:android.Manifest.permission#ACCESS_COARSE_UPDATES
     * 
     * @return 附近的电话的信息
     */
    public static List<NeighboringCellInfo> getNeighboringCellInfo(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
        if (tm != null) {

            return tm.getNeighboringCellInfo();

        }
        return null;
    }

    /**
     * 获取ISO标准的国家码,即国际长途区号。 注意:仅当用户已在网络注册后有效。 在CDMA网络中结果也许不可靠。
     * 
     * @return 长途区号
     */
    public static String getNetworkCountryIso(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
        if (tm != null) {

            return tm.getNetworkCountryIso();

        }
        return null;
    }

    /**
     * MCC+MNC(mobile country code + mobile network code) 注意:仅当用户已在网络注册时有效。 在CDMA网络中结果也许不可靠。
     * 
     * @return 手机号
     */
    public static String getNetworkOperator(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
        if (tm != null) {

            return tm.getNetworkOperator();

        }
        return null;
    }

    /**
     * 按照字母次序的current registered operator(当前已注册的用户)的名字 注意:仅当用户已在网络注册时有效。 在CDMA网络中结果也许不可靠。
     * 
     * @return 手机号
     */
    public static String getNetworkOperatorName(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
        if (tm != null) {

            return tm.getNetworkOperatorName();

        }
        return null;
    }

    /**
     * 当前使用的网络类型:
     * 例如: 
     * NETWORK_TYPE_UNKNOWN 网络类型未知 0 
     * NETWORK_TYPE_GPRS GPRS网络 1 
     * NETWORK_TYPE_EDGE EDGE网络 2
     * NETWORK_TYPE_UMTS UMTS网络 3 
     * NETWORK_TYPE_CDMA CDMA网络,IS95A或 IS95B. 4 
     * NETWORK_TYPE_EVDO_0 EVDO网络, revision 0. 5 
     * NETWORK_TYPE_EVDO_A EVDO网络, revision A. 6 
     * NETWORK_TYPE_1xRTT 1xRTT网络 7
     * NETWORK_TYPE_HSDPA HSDPA网络 8 
     * NETWORK_TYPE_HSUPA HSUPA网络 9 
     * NETWORK_TYPE_HSPA HSPA网络 10 
     *
     * @return 手机号
     */
    public static Integer getNetworkType(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
        if (tm != null) {

            return tm.getNetworkType();

        }
        return null;
    }

    /**
     * 手机类型: 例如: PHONE_TYPE_NONE 无信号 PHONE_TYPE_GSM GSM信号 PHONE_TYPE_CDMA CDMA信号
     * 
     * @return 手机类型
     */
    public static Integer getPhoneType(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
        if (tm != null) {

            return tm.getPhoneType();

        }
        return null;
    }

    /**
     * Returns the ISO country code equivalent for the SIM provider's country code. 获取ISO国家码,相当于提供SIM卡的国家码
     * 
     * @return ISO国家码
     */
    public static String getSimCountryIso(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
        if (tm != null) {

            return tm.getSimCountryIso();

        }
        return null;
    }

    /**
     * Returns the MCC+MNC (mobile country code + mobile network code) of the provider of the SIM. 5 or 6 decimal digits. 获取SIM卡提供的移动国家码和移动网络码.5或6位的十进制数字. SIM卡的状态必须是 SIM_STATE_READY(使用getSimState()判断).
     * 
     * @return SIM卡提供的移动国家码和移动网络码
     */
    public static String getSimOperator(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
        if (tm != null) {

            return tm.getSimOperator();

        }
        return null;
    }

    /**
     * 服务商名称: 例如:中国移动、联通 SIM卡的状态必须是 SIM_STATE_READY(使用getSimState()判断).
     * 
     * @return 服务商名称
     */
    public static String getSimOperatorName(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
        if (tm != null) {

            return tm.getSimOperatorName();

        }
        return null;
    }

    /**
     * SIM卡的序列号: 需要权限:READ_PHONE_STATE
     * 
     * @return SIM卡的序列号
     */
    public static String getSimSerialNumber(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
        if (tm != null) {

            return tm.getSimSerialNumber();

        }
        return null;
    }

    /*
     * SIM的状态信息: SIM_STATE_UNKNOWN 未知状态 0 
     * SIM_STATE_ABSENT 没插卡 1 
     * SIM_STATE_PIN_REQUIRED 锁定状态,需要用户的PIN码解锁 2 
     * SIM_STATE_PUK_REQUIRED 锁定状态,需要用户的PUK码解锁 3 
     * SIM_STATE_NETWORK_LOCKED 锁定状态,需要网络的PIN码解锁 4
     *  SIM_STATE_READY 就绪状态 5
     */
    public static Integer getSimState(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
        if (tm != null) {
            
            int simState = tm.getSimState();

            if (simState == 0) {
                System.out.println("SIM的状态信息: SIM_STATE_UNKNOWN 未知状态 0");
            } else if (simState == 1) {
                System.out.println("SIM的状态信息: SIM_STATE_ABSENT 没插卡 1");
            } else if (simState == 2) {
                System.out.println("SIM_STATE_PIN_REQUIRED 锁定状态,需要用户的PIN码解锁 2");
            } else if (simState == 3) {
                System.out.println("SIM_STATE_PUK_REQUIRED 锁定状态,需要用户的PUK码解锁 3");
            } else if (simState == 4) {
                System.out.println("SIM_STATE_NETWORK_LOCKED 锁定状态,需要网络的PIN码解锁 4");
            } else if (simState == 5) {
                System.out.println("SIM_STATE_READY 就绪状态 5");
            }

            return tm.getSimState();

        }
        return null;
    }

    /**
     * 唯一的用户ID: 例如:IMSI(国际移动用户识别码) for a GSM phone. 需要权限:READ_PHONE_STATE
     * 
     * @return 唯一的用户ID
     */
    public static String getSubscriberId(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
        if (tm != null) {

            return tm.getSubscriberId();

        }
        return null;
    }

    /**
     * 取得和语音邮件相关的标签,即为识别符 需要权限:READ_PHONE_STATE
     * 
     * @return 识别符
     */
    public static String getVoiceMailAlphaTag(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
        if (tm != null) {

            return tm.getVoiceMailAlphaTag();

        }
        return null;
    }

    /**
     * 获取语音邮件号码: 需要权限:READ_PHONE_STATE
     * 
     * @return 语音邮件号码
     */
    public static String getVoiceMailNumber(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
        if (tm != null) {

            return tm.getVoiceMailNumber();

        }
        return null;
    }

    /**
     * ICC卡是否存在
     * 
     * @return boolean
     */
    public static boolean hasIccCard(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
        if (tm != null) {

            return tm.hasIccCard();

        }
        return (Boolean) null;
    }

    /**
     * 是否漫游: (在GSM用途下))
     * 
     * @return 手机号
     */
    public static boolean isNetworkRoaming(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
        if (tm != null) {

            return tm.isNetworkRoaming();

        }
        return (Boolean) null;
    }

    /** 其获取WiFi 信息*/
    private static String getConnectWifiSsid(){

        WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);

        WifiInfo wifiInfo = wifiManager.getConnectionInfo();

        Log.d("打印,wifiInfo------", wifiInfo.toString());

        Log.d("打印,SSID------", wifiInfo.getSSID());

        return wifiInfo.getSSID();

    }
}

系统信息

        //系统版本
        String release = Build.VERSION.RELEASE;
        //设备型号
        String model = Build.MODEL;
        //主板名称
        String board = Build.BOARD;
        //设备品牌
        String brand = Build.BRAND;
        //设备参数
        String device = Build.DEVICE;
        //硬件名
        String hardware = Build.HARDWARE;
        //产品名称
        String product = Build.PRODUCT;
        // 描述Build的标签
        String tags = Build.TAGS;
        //builder类型
        String type = Build.TYPE;
        // 执行代码编译的User值
        String user = Build.USER;
        String[] supportedAbis = Build.SUPPORTED_ABIS;
        // 显示屏参数
        String display = Build.DISPLAY;
        // 系统编译时间
        long time = Build.TIME;
        // 获取 处理器类型
        String cpuAbi = Build.CPU_ABI;
        String cpuAbi2 = Build.CPU_ABI2;

 

    /**
     *  获取 Flash 内存空间
     * return String
     */
    public  long getTotalInternalMemorySize() {
        File path = Environment.getDataDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = stat.getBlockSize();
        long totalBlocks = stat.getBlockCount();
        return totalBlocks * blockSize;
    }

    public static String getTotalRAM() {
        RandomAccessFile reader = null;
        String load = null;
        try {
            reader = new RandomAccessFile("/proc/meminfo", "r");
            load = reader.readLine();
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            // Streams.close(reader);
        }
        return load;
    }

    /**
     * CORE-VER
     * 内核版本
     * return String
     */
    public static String getLinuxCore_Ver() {
        Process process = null;
        String kernelVersion = "";
        try {
            process = Runtime.getRuntime().exec("cat /proc/version");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        // get the output line
        InputStream outs = process.getInputStream();
        InputStreamReader isrout = new InputStreamReader(outs);
        BufferedReader brout = new BufferedReader(isrout, 8 * 1024);

        String result = "";
        String line;
        // get the whole standard output string
        try {
            while ((line = brout.readLine()) != null) {
                result += line;
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            if (result != "") {
                String Keyword = "version ";
                int index = result.indexOf(Keyword);
                line = result.substring(index + Keyword.length());
                index = line.indexOf(" ");
                kernelVersion = line.substring(0, index);
            }
        } catch (IndexOutOfBoundsException e) {
            e.printStackTrace();
        }
        return kernelVersion;
    }

    /**
     * 设备的软件版本号: 
     *
     * @return 软件版本号
     */
    @SuppressLint("MissingPermission")
    public static String getDeviceSoftwareVersion(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
        if (tm != null) {
            return tm.getDeviceSoftwareVersion();
        }
        return null;
    }

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值