获取sim卡号码
2014-04-25 16:24
162 查看
package com.pei.activity; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; /** * class name:AndroidUtilActivity<BR> * class description:show get sim card info activity<BR> * PS:注意权限 <BR> * Date:2012-3-12<BR> * @version 1.00 * @author CODYY)peijiangping */ public class AndroidUtilActivity extends Activity { private Button button_getSIMInfo; private TextView number; private TextView privoid; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button_getSIMInfo = (Button) this.findViewById(R.id.getSIMInfo); number = (TextView) this.findViewById(R.id.textView1); privoid = (TextView) this.findViewById(R.id.textView2); button_getSIMInfo.setOnClickListener(new ButtonListener()); } class ButtonListener implements OnClickListener { @Override public void onClick(View v) { if (v == button_getSIMInfo) { SIMCardInfo siminfo = new SIMCardInfo(AndroidUtilActivity.this); System.out.println(siminfo.getProvidersName()); System.out.println(siminfo.getNativePhoneNumber()); number.setText(siminfo.getNativePhoneNumber()); privoid.setText(siminfo.getProvidersName()); } } } }
实现类:
package com.pei.activity; import android.content.Context; import android.telephony.TelephonyManager; /** * class name:SIMCardInfo<BR> * class description:读取Sim卡信息<BR> * PS: 必须在加入各种权限 <BR> * Date:2012-3-12<BR> * * @version 1.00 * @author CODYY)peijiangping */ public class SIMCardInfo { /** * TelephonyManager提供设备上获取通讯服务信息的入口。 应用程序可以使用这个类方法确定的电信服务商和国家 以及某些类型的用户访问信息。 * 应用程序也可以注册一个监听器到电话收状态的变化。不需要直接实例化这个类 * 使用Context.getSystemService(Context.TELEPHONY_SERVICE)来获取这个类的实例。 */ private TelephonyManager telephonyManager; /** * 国际移动用户识别码 */ private String IMSI; public SIMCardInfo(Context context) { telephonyManager = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); } /** * Role:获取当前设置的电话号码 * <BR>Date:2012-3-12 * <BR>@author CODYY)peijiangping */ public String getNativePhoneNumber() { String NativePhoneNumber=null; NativePhoneNumber=telephonyManager.getLine1Number(); return NativePhoneNumber; } /** * Role:Telecom service providers获取手机服务商信息 <BR> * 需要加入权限<uses-permission * android:name="android.permission.READ_PHONE_STATE"/> <BR> * Date:2012-3-12 <BR> * * @author CODYY)peijiangping */ public String getProvidersName() { String ProvidersName = null; // 返回唯一的用户ID;就是这张卡的编号神马的 IMSI = telephonyManager.getSubscriberId(); // IMSI号前面3位460是国家,紧接着后面2位00 02是中国移动,01是中国联通,03是中国电信。 System.out.println(IMSI); if (IMSI.startsWith("46000") || IMSI.startsWith("46002")) { ProvidersName = "中国移动"; } else if (IMSI.startsWith("46001")) { ProvidersName = "中国联通"; } else if (IMSI.startsWith("46003")) { ProvidersName = "中国电信"; } return ProvidersName; } }
xml文件:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:gravity="center"> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> <Button android:id="@+id/getSIMInfo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="获取手机号码等信息" /> </LinearLayout>
效果图如下:
相关文章推荐
- Android上获取SIM卡号码
- MTK根据SIM卡slotId获取可以保存名字和号码的最大长度
- 获取手机号码/判断Sim卡状态
- Android本机号码及Sim卡状态的获取
- android获取手机的所有通讯录的号码和sim卡号码
- 获取手机sim卡的属性号码
- 点击短信内容,获取短信内的号码和链接
- 获取手机号码联系人,短信信息
- Android手机号码获取问题
- 小程序getPhoneNumber获取微信绑定手机号码,获取用户微信认证时的手机号——玩转小程序113
- C# 根据身份证号码获取简易信息
- 通过Httpclient的get,post获取手机号码信息
- Android 获取SIM卡手机号
- 获取手机的手机号码
- 自己的服务解密,获取微信小程序用户的手机号码
- 获取Android短信草稿箱号码为空的解决办法
- 如何获取手机号码?
- 点击短信内容,获取短信内的号码和链接(2)
- php获取手机号码归属地
- 【小功能2】android获取手机信息(号码,内存,CPU,分辨率,MAC,IP,SD卡,IMEI,经纬度,信号强度等等)