获取手机号码信息以及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中attr自定义标签详解
  2. android listview 右滑删除(android 项目心得五)
  3. android tools命名空间
  4. Android获得全局进程信息以及进程使用的内存情况
  5. Android(安卓)获取设备各种信息以及其它
  6. Android(安卓)中使用自定义字体的方法
  7. Android查看内存和CPU~
  8. Android(安卓)AlertDialog的基本使用方法
  9. Android中贪吃蛇游戏的学习(四)

随机推荐

  1. android 判断横竖屏的方法
  2. android之Matrix
  3. Android中的Message类以及Java对象池的实
  4. 2011.09.07——— android zxing 条形码
  5. android 9.0 增加实体按键的按键声音,以及
  6. android 创建快捷方式图标
  7. android源码分享之蓝虫火车票余票查询源
  8. android与webservice通信之中文乱码问题!
  9. android通过shape.xml制作渐变背景
  10. Android listview中使用button解决方法