Note: obtain basic information such as mobile phone numbers ., Note Basic Information
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 @ Override14 protected void onCreate (Bundle savedInstanceState) {15 super. onCreate (savedInstanceState); 16 setContentView (R. layout. activity_main); 17 StringBuffer sb; 18 // Get Mobile Phone Manager 19 TelephonyManager mTelephonyManager = (TelephonyManager) getSystemService (Context. TELEPHONY_SERVICE); 20 // get the mobile phone number 21 String phoneNumber = mTelephonyManager. getLine1Number (); 22 // obtain the mobile phone model 23 String phoneModel = Build. MODEL; 24 // get sdk version 25 String sdk = Build. VERSION. SDK; 26 // get the mobile phone system version 27 String phoneSystem = Build. VERSION. RELEASE; 28 29 sb = new StringBuffer (); 30 31 sb. append ("mobile phone number:" + phoneNumber + "\ n" + "Mobile Phone model:" + phoneModel + "\ n" + "SDK version: "+ sdk +" \ n "+" Mobile Phone System Version: "+ phoneSystem); 32 33 TextView TV = (TextView) findViewById (R. id. TV); 34 TV. setText (sb); 35 36 37} 38 39}
Do not forget the permission:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />