android系统信息获取

本文介绍了如何通过Build.VERSION.SDK_INT常量获取Android设备的SDK版本,例如Android 6.0对应值为23。
摘要由CSDN通过智能技术生成

String version_sdk = Build.VERSION.SDK_INT; // 设备SDK版本(Android版本号)如:23(android 6.0)

String version_release = Build.VERSION.RELEASE; // 设备的系统版本
// 获取设备号
TelephonyManager var1 = (TelephonyManager)getApplicationContext().getSystemService(TELEPHONY_SERVICE);
String deviceId = var1.getDeviceId();
在Android平台中,通过TelephonyManager可以访问与手机通讯相关的信息,比如设备信息、网络信息及SIM卡信息,同时还可以监听电话的相关状态。下面我们通过几个方面来说明Android平台中如何使用电话技术。


1、获取TelephonyManager对象
TelephonyManager类提供的主要的方法:


 


Public Methods


int           


getCallState()


返回一个常数,表示设备上的呼叫状态


CellLocation           


getCellLocation()


返回设备的当前位置。


int           


getDataActivity()


返回一个常数,表示活动的数据连接的类型。


int           


getDataState()


返回一个常数表示当前数据连接状态 


String            


getDeviceId()


返回唯一的设备ID,例如,IMEI GSM和MEID CDMA手机。

String           

getDeviceSoftwareVersion()

返回设备的软件版本号,例如,的IMEI / SV GSM手机。

String           


getLine1Number()


返回1号线的电话号码,例如,MSISDN用于GSM电话。


List<NeighboringCellInfo>       


getNeighboringCellInfo()


返回设备的相邻小区信息。


String         


getNetworkCountryIso()


返回注册的网络运营商的国家代码


String           


getNetworkOperator()


返回的MCC +跨国公司的注册网络运营商


String          


getNetworkOperatorName()


返回注册的网络运营商的名字


int          


getNetworkType()


返回一个常数,表示目前在设备上使用的无线电技术(网络类型)。


int          


getPhoneType()


返回设备的类型(手机制式)。


String          


getSimCountryIso()


 返回SIM卡运营商的国家代码


String          


getSimOperator()


返回MCC +跨国公司(移动国家代码+移动网络代码)的提供者的SIM卡。


String          


getSimOperatorName()


返回服务提供者的名称(SPN)。


String          


getSimSerialNumber()


返回SIM卡的序列号,如果适用的话。


int          


getSimState()


返回一个常数表示SIM卡设备的状态。


String          


getSubscriberId()


返回唯一的用户ID,例如,IMSI为GSM手机。


String          


getVoiceMailAlphaTag()


检索与语音信箱号码相关的字母标识符。


String          


getVoiceMailNumber()


返回语音信箱号码。


boolean          


hasIccCard()


boolean          


isNetworkRoaming()


返回true,如果该设备被认为是漫游当前网络上,支持GSM目的。


void          


listen(PhoneStateListener listener, int events)


注册一个侦听器对象接收改变指定的电话状态的通知。


TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
2、通过TelephonyManager获取设备信息


String phoneTypeStr = "未知";
int phoneType = telephonyManager.getPhoneType();
switch (phoneType){
	case TelephonyManager.PHONE_TYPE_CDMA:
		phoneTypeStr="CDMA";
		break;
	case TelephonyManager.PHONE_TYPE_GSM:
		phoneTypeStr="GSM";
		break;
	case TelephonyManager.PHONE_TYPE_SIP:
		phoneTypeStr="SIP";
		break;
	case TelephonyManager.PHONE_TYPE_NONE:
		phoneTypeStr="None";
		break;
}
addTelephoneView("电话类型",phoneTypeStr);
//GSM--IMEI  CDMA--MEID
String deviceId = telephonyManager.getDeviceId();
addTelephoneView("设备编号",deviceId);
//软件版本编号
String softVersion = telephonyManager.getDeviceSoftwareVersion();
addTelephoneView("软件版本",softVersion);
//手机号码(不一定能获取到)
String phoneNumber = telephonyManager.getLine1Number();
addTelephoneView("手机号码",phoneNumber);
3、通过TelephonyManager获取网络信息
     
       
//网络信息:连接到一个网络时有效,如果是CDMA则不一定有效
//国家ISO代码
String networkCountry = telephonyManager.getNetworkCountryIso();
addTelephoneView("国家ISO代码",networkCountry);
//运营商信息
String networkOperatorId = telephonyManager.getNetworkOperator();
addTelephoneView("运营商编号",networkOperatorId);
String networkOperatorName=telephonyManager.getNetworkOperatorName();
addTelephoneView("运营商名称",networkOperatorName);
//网络连接状态
int  networktype = telephonyManager.getNetworkType();
addTelephoneView("网络类型",ne
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值