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"/>

 

你可能感兴趣的:(android)