获取手机号码信息以及imsi信息,需要的权限为

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

package com.phoneinfotest;import android.app.Activity;import android.os.Bundle;import android.telephony.TelephonyManager;import android.view.View;import android.view.View.OnClickListener;import android.view.ViewGroup.LayoutParams;import android.widget.Button;import android.widget.LinearLayout;import android.widget.TextView;public class MainActivity extends Activity {private TextView textMobile;private TextView textImsi;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);LinearLayout linearLayout = new LinearLayout(this);linearLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));linearLayout.setOrientation(LinearLayout.VERTICAL);Button button = new Button(this);button.setText("获取手机信息");button.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View arg0) {TelephonyManager telephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);textMobile.setText(telephonyManager.getLine1Number());textImsi.setText(telephonyManager.getSubscriberId());}});LinearLayout mobileLayout = new LinearLayout(this);mobileLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));mobileLayout.setOrientation(LinearLayout.HORIZONTAL);TextView labelMobile = new TextView(this);labelMobile.setText("手机号码:");textMobile = new TextView(this);mobileLayout.addView(labelMobile);mobileLayout.addView(textMobile);/** * IMSI共有15位,其结构如下: * MCC+MNC+MSIN * MCC:Mobile Country Code,移动国家码,MCC的资源由国际电联(ITU)统一分配和管理,唯一识别移动用户所属的国家,共3位,中国为460; * MNC:Mobile Network Code,移动网络码,2~3位,中国移动系统使用00、02、07,中国联通GSM系统使用01、06,中国电信CDMA系统使用03、05,中国铁通系统使用20,一个典型的IMSI号码为460030912121001; */LinearLayout imsiLayout = new LinearLayout(this);imsiLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));imsiLayout.setOrientation(LinearLayout.HORIZONTAL);TextView labelImsi = new TextView(this);labelImsi.setText("imsi:");textImsi = new TextView(this);imsiLayout.addView(labelImsi);imsiLayout.addView(textImsi);linearLayout.addView(button);linearLayout.addView(mobileLayout);linearLayout.addView(imsiLayout);setContentView(linearLayout);}}

更多相关文章

  1. android 系统属性 build.prop
  2. Android 系统音量最大值的定义位置以及默认值的修改方法
  3. android 系统关机,重启
  4. 在4.0以上系统中应用出现2.3版本的系统UI
  5. 修改系统分辨率
  6. android系统信息总结
  7. [置顶] Android编译系统详解(一)
  8. Android图形系统(八)-app与SurfaceFlinger共享UI元数据过程
  9. Android日志系统Logcat源代码简要分析

随机推荐

  1. Android - under the hood
  2. android创建通知栏(java版)
  3. Android学习笔记(7)————Android中的
  4. android电量状态获取
  5. 多线程例子 android camera capture
  6. Android各类路径获取方式
  7. android Progressbar浣跨敤
  8. android 对话框实例
  9. ViewPager fragment android tab选项卡的
  10. Android生命周期的学习