版权声明:注明转载出处 https://blog.csdn.net/qq_38629981/article/details/80563958
package com.lixue.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 xiewencai 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_HSDPA HSDPA网络 8 NETWORK_TYPE_HSUPA HSUPA网络 9 NETWORK_TYPE_HSPA HSPA网络 10 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
*
* @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;
}
}