android 獲取手機信息
- 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";// 帶毫秒和時區的時間格式
- 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 date, String format) {
- DateFormat dateFormat = new SimpleDateFormat(format);
- return dateFormat.format(date);
- }
-
- // 取得device的IP address
- private String getIp() {
- WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
- WifiInfo wifiInfo = wifiManager.getConnectionInfo();
- int ipAddress = wifiInfo.getIpAddress();
-
- // 格式化IP address,例如:格式化前:1828825280,格式化後:192.168.1.109
- String ip = String.format("%d.%d.%d.%d",
- (ipAddress & 0xff),
- (ipAddress >> 8 & 0xff),
- (ipAddress >> 16 & 0xff),
- (ipAddress >> 24 & 0xff));
- return ip;
-
- }
-
- //獲取device的os version
- private String getosVersion() {
- String version = android.os.Build.VERSION.RELEASE;
- return version;
- }
- }
歡迎關注本站公眾號,獲取更多信息