android获取手机号码以及imsi信息
16lz
2021-12-04
获取手机号码信息以及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);}}
更多相关文章
- Android中attr自定义标签详解
- android listview 右滑删除(android 项目心得五)
- android tools命名空间
- Android获得全局进程信息以及进程使用的内存情况
- Android(安卓)获取设备各种信息以及其它
- Android(安卓)中使用自定义字体的方法
- Android查看内存和CPU~
- Android(安卓)AlertDialog的基本使用方法
- Android中贪吃蛇游戏的学习(四)