Android obtains the mobile phone information (device IP, OS version etc .) I haven't written anything for a long time. Today I am making a PV log record. I need to record the OS version, WiFi IP address, current time, and so on. I have investigated and shared the following:
Package com. Osip;
Import java. Text. dateformat;
Import java. Text. simpledateformat;
Import java. util. date;
Import Android. App. activity;
Import android.net. Wifi. wifiinfo;
Import android.net. Wifi. wifimanager;
Import Android. OS. Bundle;
Import Android. widget. textview;
Public class Osip extends activity {
Private textview osversion, clientip, date;
/** Called when the activity is first created .*/
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
Osversion = (textview) findviewbyid (R. Id. OS _version );
Clientip = (textview) findviewbyid (R. Id. client_ip );
Date = (textview) findviewbyid (R. Id. date );
String format = "yyyymmdd. hhmmss. sssz"; // time format with milliseconds and Time Zone
String version = getosversion ();
String IP = getip ();
String cdate = getdate (new date (), format );
Osversion. settext (version );
Clientip. settext (IP );
Date. settext (cdate. substring (0, 22 ));
}
Private string getdate (date, string format ){
Dateformat = new simpledateformat (format );
Return dateformat. Format (date );
}
// Obtain the IP address of the device
Private string getip (){
Wifimanager = (wifimanager) getsystemservice (wifi_service );
Wifiinfo = wifimanager. getconnectioninfo ();
Int IPaddress = wifiinfo. getipaddress ();
// Format the IP address, for example, 1828825280 before formatting and 192.168.1.109 after formatting
String IP = string. Format ("% d. % d ",
(IPaddress & 0xff ),
(IPaddress> 8 & 0xff ),
(IPaddress> 16 & 0xff ),
(IPaddress> 24 & 0xff ));
Return IP;
}
// Obtain the OS version of the device
Private string getosversion (){
String version = Android. OS. Build. version. release;
Return version;
}
}