android使用TelephonyManager获取imei和其他手机信息
2016-06-07 10:19
573 查看
在AndroidManifest.xml文件中增加
<!--允许读取电话状态SIM的权限--> <uses-permission android:name="android.permission.READ_PHONE_STATE" />
代码如下
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); //手机串号:GSM手机的IMEI 和 CDMA手机的 MEID. String deviceID = telephonyManager.getDeviceId(); //手机号(有些手机号无法获取,是因为运营商在SIM中没有写入手机号) String tel = telephonyManager.getLine1Number(); //获取手机SIM卡的序列号 /** * Returns the serial number of the SIM, if applicable. Return null if it is * unavailable. * <p> * Requires Permission: * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} */ String simSerialNumber = telephonyManager.getSimSerialNumber(); /** * Returns the unique subscriber ID, for example, the IMSI for a GSM phone. * Return null if it is unavailable. * <p> * Requires Permission: * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} */ //获取客户id,在gsm中是imsi号 String imsi = telephonyManager.getSubscriberId(); /** * Returns the current location of the device. *<p> * If there is only one radio in the device and that radio has an LTE connection, * this method will return null. The implementation must not to try add LTE * identifiers into the existing cdma/gsm classes. *<p> * In the future this call will be deprecated. *<p> * @return Current location of the device or null if not available. * * <p>Requires Permission: * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_COARSE_LOCATION} or * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION}. */ //电话方位 CellLocation str = telephonyManager.getCellLocation(); /** * Returns the alphabetic name of current registered operator. * <p> * Availability: Only when user is registered to a network. Result may be * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if * on a CDMA network). */ //运营商名称,注意:仅当用户已在网络注册时有效,在CDMA网络中结果也许不可靠 String networkoperatorName = telephonyManager.getNetworkOperatorName(); /** * Retrieves the alphabetic identifier associated with the voice * mail number. * <p> * Requires Permission: * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} */ //取得和语音邮件相关的标签,即为识别符 String voiceMail = telephonyManager.getVoiceMailAlphaTag(); /** * Returns the voice mail number. Return null if it is unavailable. * <p> * Requires Permission: * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} */ //获取语音邮件号码: String voiceMailNumber = telephonyManager.getVoiceMailNumber(); /** * Returns the ISO country code equivalent for the SIM provider's country code. */ //获取ISO国家码,相当于提供SIM卡的国家码。 String simCountryIso = telephonyManager.getSimCountryIso(); /** * Returns one of the following constants that represents the current state of all * phone calls. * * {@link TelephonyManager#CALL_STATE_RINGING}响铃 * {@link TelephonyManager#CALL_STATE_OFFHOOK}摘机(占用)状态 * {@link TelephonyManager#CALL_STATE_IDLE}无活动 */ int callState = telephonyManager.getCallState(); /** * 设备的软件版本号: * Returns the software version number for the device, for example, * the IMEI/SV for GSM phones. Return null if the software version is * not available. * * <p>Requires Permission: * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} */ String devicesoftware = telephonyManager.getDeviceSoftwareVersion(); /** * Returns the ISO country code equivalent of the current registered * operator's MCC (Mobile Country Code).获取ISO标准的国家码,即国际长途区号。 * <p> * Availability: Only when user is registered to a network. Result may be * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if * on a CDMA network). */ String networkCountry = telephonyManager.getNetworkCountryIso(); /** * Returns the numeric name (MCC+MNC) of current registered operator. * <p>(mobile country code + mobile network code) * Availability: Only when user is registered to a network. Result may be * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if * on a CDMA network). */ String networkoperator = telephonyManager.getNetworkOperator(); /** * @return the NETWORK_TYPE_xxxx for current data connection. * 当前使用的网络类型: * 例如: 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 */ int netWorkType = telephonyManager.getNetworkType(); /** * Returns a constant indicating the device phone type. This * indicates the type of radio used to transmit voice calls. * * @see #PHONE_TYPE_NONE * @see #PHONE_TYPE_GSM * @see #PHONE_TYPE_CDMA * @see #PHONE_TYPE_SIP */ int phoneType = telephonyManager.getPhoneType(); /** * 获取SIM卡提供的移动国家码和移动网络码.5或6位的十进制数字. * Returns the MCC+MNC (mobile country code + mobile network code) of the * provider of the SIM. 5 or 6 decimal digits. * <p> * Availability: SIM state must be {@link #SIM_STATE_READY} *SIM卡的状态必须是 SIM_STATE_READY(使用getSimState()判断). * @see #getSimState */ String simOperator = telephonyManager.getSimOperator(); /** * 服务商名称: * Returns the Service Provider Name (SPN). * <p> * Availability: SIM state must be {@link #SIM_STATE_READY} *SIM卡的状态必须是 SIM_STATE_READY(使用getSimState()判断). * @see #getSimState */ String simOperatorName = telephonyManager.getSimOperatorName(); /** * Returns a constant indicating the state of the default SIM card. *SIM的状态信息: * @see #SIM_STATE_UNKNOWN * @see #SIM_STATE_ABSENT * @see #SIM_STATE_PIN_REQUIRED * @see #SIM_STATE_PUK_REQUIRED * @see #SIM_STATE_NETWORK_LOCKED * @see #SIM_STATE_READY * @see #SIM_STATE_NOT_READY * @see #SIM_STATE_PERM_DISABLED * @see #SIM_STATE_CARD_IO_ERROR */ int simStat = telephonyManager.getSimState(); /** * @return true if a ICC card is present */ boolean hasIcc = telephonyManager.hasIccCard(); /** * 是否漫游: * (在GSM用途下) * Availability: Only when user registered to a network. */ boolean isRoaming = telephonyManager.isNetworkRoaming(); /** * 附近的电话的信息: * 类型:List<NeighboringCellInfo> * 需要权限:android.Manifest.permission#ACCESS_COARSE_UPDATES */ List<NeighboringCellInfo> list = telephonyManager.getNeighboringCellInfo();//List<NeighboringCellInfo> /** * 获取数据连接状态 * @see #DATA_ACTIVITY_NONE * @see #DATA_ACTIVITY_IN * @see #DATA_ACTIVITY_OUT * @see #DATA_ACTIVITY_INOUT * @see #DATA_ACTIVITY_DORMANT */ int dataActivty = telephonyManager.getDataActivity();
相关文章推荐
- Android 快速开发系列 打造万能的ListView GridView 适配器
- android 简单的Edittext特效,悬浮标签
- 安卓LOG封装类
- Android官方开发文档Training系列课程中文版:连接无线设备之通过WIFI创建P2P连接
- Android项目启动时短暂的黑屏白屏处理
- Android Studio 修改包名packageName
- 捕获Home键
- AndroidStudio一个工程内查看多个项目的实现
- Android 手势锁的实现 与详细的代码注释
- 百度地图(一)—————让百度地图显示在自己的软件上
- android 4.4编译问题求解
- 安卓获取设备详细信息
- Android之Chronometer
- 带头部可折叠的ListVivew
- Android开发之自定义组件和接口回调
- Android Double类型数据保留两位小数
- Android 自定义View步骤
- android学习之存储篇_SQLite数据库、SQLite学习看我就够了
- Android 自定义View 密码框实例代码
- Android-Universal-Image-Loader 图片异步加载类库的使用(超详细配置)