代码如下:
package com.zzw.getPhoneInfos;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 获取电话管理对象
TelephonyManager mTelephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
// 获取手机号码
String phoneNumber = mTelephonyManager.getLine1Number();
Log.d("获取本机电话号码--->", phoneNumber);
// 获取手机型号
String phoneModel = Build.MODEL;
Log.d("获取手机型号--->", phoneModel);
// 获取SDK版本
String phoneSdkVersion = Build.VERSION.SDK;
Log.d("获取SDK版本--->", phoneSdkVersion);
// 获取系统版本
String phoneReleaseVersion = Build.VERSION.RELEASE;
Log.d("获取手机系统版本-->", phoneReleaseVersion);
}
}
不要忘记权限:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
结果如图: