Summary of mobile phone system information, mobile phone system information
Get IMEI number:
/*** Get the IMEI number ** @ Description: * @ param activity * @ param @ return * @ return String */public static String getIMEI (Activity activity) {TelephonyManager manager = (TelephonyManager) activity. getSystemService (Context. TELEPHONY_SERVICE); return manager. getDeviceId ();}
Get IMSI:
/*** Get IMSI ** @ Description: * @ param activity * @ param @ return * @ return String */public static String getIMSI (Activity activity) {TelephonyManager manager = (TelephonyManager) activity. getSystemService (Context. TELEPHONY_SERVICE); return manager. getSubscriberId ();}
Mobile phone model:
/*** Mobile phone MODEL ** @ Description: * @ param @ return * @ return String */public static String getPhoneModel () {return android. OS. Build. MODEL ;}
System Version Number (numeric value ):
/*** System VERSION Number (numeric value) ** @ Description: * @ param @ return * @ return int */public static int getPhoneSdkVersionInt () {return Build. VERSION. SDK_INT ;}
System Version (string)
/*** System VERSION Number (String) ** @ Description: * @ param @ return * @ return String */public static String getPhoneSDKVersionChar () {return Build. VERSION. RELEASE ;}
APP version (string ):
/*** @ Description: APP version number (String) * @ param activity * @ param @ return * @ return String */public static String getAppVersionChars (Activity activity) {PackageManager packageManager = activity. getPackageManager (); PackageInfo packageInfo = null; try {packageInfo = packageManager. getPackageInfo (activity. getPackageName (), 0);} catch (NameNotFoundException e) {// TODO Auto-generated catch blocke. printStackTrace ();} return packageInfo. versionName ;}
APP version (integer ):
/*** APP version number (integer) ** @ Description: * @ param activity * @ param @ return * @ return int */public static int getAppVersionInt (Activity activity) {PackageManager packageManager = activity. getPackageManager (); PackageInfo packageInfo = null; try {packageInfo = packageManager. getPackageInfo (activity. getPackageName (), 0);} catch (NameNotFoundException e) {// TODO Auto-generated catch blocke. printStackTrace ();} return packageInfo. versionCode ;}
Obtain the Internet IP address (ip168 is unstable. You can obtain other IP addresses. The principle is similar ):
/*** Get Internet IP ** @ Description: * @ param @ return * @ return String */public static String GetNetIp () {URL infoUrl = null; InputStream inStream = null; string ipLine = ""; HttpURLConnection httpConnection = null; try {infoUrl = new URL ("http://ip168.com/"); URLConnection connection = infoUrl. openConnection (); httpConnection = (HttpURLConnection) connection; int responseCode = httpConnection. getResponseCode (); If (responseCode = HttpURLConnection. HTTP_ OK) {inStream = httpConnection. getInputStream (); BufferedReader reader = new BufferedReader (new InputStreamReader (inStream, "UTF-8"); StringBuilder strber = new StringBuilder (); String line = null; while (line = reader. readLine ())! = Null) strber. append (line + "\ n"); Pattern pattern = Pattern. compile ("((? :(?: 25 [0-5] | 2 [0-4] \ d | (1 \ d {2}) | ([1-9]? \ D) \.) {3 }(?: 25 [0-5] | 2 [0-4] \ d | (1 \ d {2}) | ([1-9]? \ D) "); Matcher matcher = pattern. matcher (strber. toString (); if (matcher. find () {ipLine = matcher. group () ;}} catch (MalformedURLException e) {e. printStackTrace ();} catch (IOException e) {e. printStackTrace ();} finally {try {if (inStream! = Null) {inStream. close ();} if (httpConnection! = Null) {httpConnection. disconnect () ;}} catch (IOException e) {e. printStackTrace () ;}} return ipLine ;}
Obtain the local IP Address:
/*** Obtain the local network IP ** @ Description: * @ param @ return * @ return String */public static String getLocalIpAddress () {try {Enumeration <NetworkInterface> en = NetworkInterface. getNetworkInterfaces (); while (en. hasMoreElements () {NetworkInterface ni = en. nextElement (); Enumeration <InetAddress> enIp = ni. getInetAddresses (); while (enIp. hasMoreElements () {InetAddress inet = enIp. nextElement (); if (! Inet. isLoopbackAddress () & (inet instanceof Inet4Address) {return inet. getHostAddress (). toString () ;}}} catch (SocketException e) {// TODO Auto-generated catch blocke. printStackTrace ();} return "0 ";}