Android获取应用程序的信息
1.获取应用程序的版本号:
private String getAppVersionName() { String versionName = ""; try { PackageManager pm = this.getPackageManager(); PackageInfo pi = pm.getPackageInfo(this.getPackageName(), 0); versionName = pi.versionName; if (versionName == null || versionName.length() <= 0) { return ""; } } catch (Exception e) { e.printStackTrace(); } return versionName; }
2.获取手机webview的useragent
private String getUserAgent() { WebView wv = new WebView(this); WebSettings settings = wv.getSettings(); String user_agent = settings.getUserAgentString(); wv.destroy(); return user_agent; }
3.获取Android设备的唯一识别码
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.getDeviceId()
4.获取手机ip
public String getLocalIpAddress() { try { for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { return inetAddress.getHostAddress().toString(); } } } } catch (SocketException ex) { Log.e(LOG_TAG, ex.toString()); } return null; }
要记得添加权限 <uses-permission android:name="android.permission.INTERNET"/>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。