代码如下:
图片如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
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());
}
}
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
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;
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
<?
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
>
|