1 package com.lixu.getphonetxt;
 2 
 3 import android.app.Activity;
 4 import android.content.Context;
 5 import android.os.Build;
 6 import android.os.Bundle;
 7 import android.telephony.TelephonyManager;
 8 import android.widget.TextView;
 9 import android.widget.Toast;
10 
11 public class MainActivity extends Activity {
12 
13     @Override
14     protected void onCreate(Bundle savedInstanceState) {
15         super.onCreate(savedInstanceState);
16         setContentView(R.layout.activity_main);
17
18 // 获取手机管理器 19 TelephonyManager mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); 20 // 获取手机号码 21 String phoneNumber = mTelephonyManager.getLine1Number(); 22 // 获取手机型号 23 String phoneModel = Build.MODEL; 24 // 获取sdk版本 25 String sdk = Build.VERSION.SDK; 26 // 获取手机系统版本 27 String phoneSystem = Build.VERSION.RELEASE; 28 29 StringBuffer sb = new StringBuffer(); 30 31 sb.append("手机号码是:" + phoneNumber + "\n"+"手机型号是:" + phoneModel +"\n"+ "SDK版本是:" + sdk + "\n"+"手机系统版本是:" + phoneSystem); 32 33 TextView tv = (TextView) findViewById(R.id.tv); 34 tv.setText(sb); 35 36 37 } 38 39 }

 

不要忘记权限:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
posted on 2015-12-18 17:13  0代码狂人0  阅读(690)  评论(0编辑  收藏  举报