Android obtains the mobile phone information (device IP, OS version etc .)

Source: Internet
Author: User
Tags dateformat
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;

}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.