http://blog.csdn.net/peijiangping1989/article/details/7344925
http://www.open-open.com/lib/view/open1331537862874.html
代码如下:
01 | package com.pei.activity; |
03 | import android.app.Activity; |
04 | import android.os.Bundle; |
05 | import android.view.View; |
06 | import android.view.View.OnClickListener; |
07 | import android.widget.Button; |
08 | import android.widget.TextView; |
11 | * class name:AndroidUtilActivity<BR> |
12 | * class description:show get sim card info activity<BR> |
16 | * @author CODYY)peijiangping |
18 | public class AndroidUtilActivity extends Activity { |
19 | private Button button_getSIMInfo; |
20 | private TextView number; |
21 | private TextView privoid; |
24 | public void onCreate(Bundle savedInstanceState) { |
25 | super .onCreate(savedInstanceState); |
26 | setContentView(R.layout.main); |
27 | button_getSIMInfo = (Button) this .findViewById(R.id.getSIMInfo); |
28 | number = (TextView) this .findViewById(R.id.textView1); |
29 | privoid = (TextView) this .findViewById(R.id.textView2); |
30 | button_getSIMInfo.setOnClickListener( new ButtonListener()); |
33 | class ButtonListener implements OnClickListener { |
36 | public void onClick(View v) { |
37 | if (v == button_getSIMInfo) { |
38 | SIMCardInfo siminfo = new SIMCardInfo(AndroidUtilActivity. this ); |
39 | System.out.println(siminfo.getProvidersName()); |
40 | System.out.println(siminfo.getNativePhoneNumber()); |
41 | number.setText(siminfo.getNativePhoneNumber()); |
42 | privoid.setText(siminfo.getProvidersName()); |
01 | package com.pei.activity; |
03 | import android.content.Context; |
04 | import android.telephony.TelephonyManager; |
07 | * class name:SIMCardInfo<BR> |
08 | * class description:读取Sim卡信息<BR> |
13 | * @author CODYY)peijiangping |
15 | public class SIMCardInfo { |
17 | * TelephonyManager提供设备上获取通讯服务信息的入口。 应用程序可以使用这个类方法确定的电信服务商和国家 以及某些类型的用户访问信息。 |
18 | * 应用程序也可以注册一个监听器到电话收状态的变化。不需要直接实例化这个类 |
19 | * 使用Context.getSystemService(Context.TELEPHONY_SERVICE)来获取这个类的实例。 |
21 | private TelephonyManager telephonyManager; |
27 | public SIMCardInfo(Context context) { |
28 | telephonyManager = (TelephonyManager) context |
29 | .getSystemService(Context.TELEPHONY_SERVICE); |
35 | * <BR>@author CODYY)peijiangping |
37 | public String getNativePhoneNumber() { |
38 | String NativePhoneNumber= null ; |
39 | NativePhoneNumber=telephonyManager.getLine1Number(); |
40 | return NativePhoneNumber; |
44 | * Role:Telecom service providers获取手机服务商信息 <BR> |
45 | * 需要加入权限<uses-permission |
46 | * android:name="android.permission.READ_PHONE_STATE"/> <BR> |
49 | * @author CODYY)peijiangping |
51 | public String getProvidersName() { |
52 | String ProvidersName = null ; |
53 | // 返回唯一的用户ID;就是这张卡的编号神马的 |
54 | IMSI = telephonyManager.getSubscriberId(); |
55 | // IMSI号前面3位460是国家,紧接着后面2位00 02是中国移动,01是中国联通,03是中国电信。 |
56 | System.out.println(IMSI); |
57 | if (IMSI.startsWith( "46000" ) || IMSI.startsWith( "46002" )) { |
58 | ProvidersName = "中国移动" ; |
59 | } else if (IMSI.startsWith( "46001" )) { |
60 | ProvidersName = "中国联通" ; |
61 | } else if (IMSI.startsWith( "46003" )) { |
62 | ProvidersName = "中国电信" ; |
01 | <? xml version = "1.0" encoding = "utf-8" ?> |
02 | < LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android" |
03 | android:layout_width = "fill_parent" |
04 | android:layout_height = "fill_parent" |
05 | android:orientation = "vertical" android:gravity = "center" > |
08 | android:id = "@+id/textView1" |
09 | android:layout_width = "wrap_content" |
10 | android:layout_height = "wrap_content" |
11 | android:text = "TextView" /> |
14 | android:id = "@+id/textView2" |
15 | android:layout_width = "wrap_content" |
16 | android:layout_height = "wrap_content" |
17 | android:text = "TextView" /> |
20 | android:id = "@+id/getSIMInfo" |
21 | android:layout_width = "wrap_content" |
22 | android:layout_height = "wrap_content" |
23 | android:text = "获取手机号码等信息" /> |
图片如下: