转自

获取IMEI等

public String getPhoneInfo(Context context) {     TelephonyManager tm = (TelephonyManager) context             .getSystemService(Context.TELEPHONY_SERVICE);     StringBuilder sb = new StringBuilder();     sb.append("\nDeviceId(IMEI) = " + tm.getDeviceId());//获取设备IMEI信息     sb.append("\nDeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion());     sb.append("\nLine1Number = " + tm.getLine1Number());     sb.append("\nNetworkCountryIso = " + tm.getNetworkCountryIso());     sb.append("\nNetworkOperator = " + tm.getNetworkOperator());     sb.append("\nNetworkOperatorName = " + tm.getNetworkOperatorName());     sb.append("\nNetworkType = " + tm.getNetworkType());     sb.append("\nPhoneType = " + tm.getPhoneType());     sb.append("\nSimCountryIso = " + tm.getSimCountryIso());     sb.append("\nSimOperator = " + tm.getSimOperator());     sb.append("\nSimOperatorName = " + tm.getSimOperatorName());     sb.append("\nSimSerialNumber = " + tm.getSimSerialNumber());     sb.append("\nSimState = " + tm.getSimState());     sb.append("\nSubscriberId(IMSI) = " + tm.getSubscriberId());     sb.append("\nVoiceMailNumber = " + tm.getVoiceMailNumber());     return sb.toString();  

}

获取屏幕的相关信息

    private int screenWidth;      private int screenHeigth;      private float screenDensity;      private int screenDpi;      private float screenScaledDensity;     public void getScreenInfo(Activity activity) {         DisplayMetrics metric = new DisplayMetrics();         activity.getWindowManager().getDefaultDisplay().getMetrics(metric);         screenWidth = metric.widthPixels;         screenHeigth = metric.heightPixels;         screenDensity = metric.density;         screenDpi = metric.densityDpi;         screenScaledDensity = metric.scaledDensity;     }  

获得屏幕的宽度

/**      * Get the screen width.      *       * @param context      * @return the screen width      */      @SuppressWarnings("deprecation")      @SuppressLint("NewApi")      public static int getScreenWidth(Activity context) {          Display display = context.getWindowManager().getDefaultDisplay();          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {              Point size = new Point();              display.getSize(size);              return size.x;          }          return display.getWidth();      }  

获取屏幕的高度

/**      * Get the screen height.      *       * @param context      * @return the screen height      */      @SuppressWarnings("deprecation")      @SuppressLint("NewApi")      public static int getScreenHeight(Activity context) {          Display display = context.getWindowManager().getDefaultDisplay();          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {              Point size = new Point();              display.getSize(size);              return size.y;          }          return display.getHeight();      }  

获取网络连接状态

public boolean isConnect(Context context) {          try {              ConnectivityManager conMan = (ConnectivityManager) context                      .getSystemService(Context.CONNECTIVITY_SERVICE);              if (null != conMan) {                  NetworkInfo mobileNetWorkInfo = conMan                          .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);                  if (mobileNetWorkInfo != null) {                      State mobile = mobileNetWorkInfo.getState();                      if (mobile != null && mobile.equals(State.CONNECTED)) {                          return true;                      }                  }                  NetworkInfo wifiNetworkInfo = conMan                          .getNetworkInfo(ConnectivityManager.TYPE_WIFI);                  if (wifiNetworkInfo != null) {                      State wifi = wifiNetworkInfo.getState();                      if (wifi != null && wifi.equals(State.CONNECTED)) {                          return true;                      }                  }              }          } catch (Exception e) {              e.getStackTrace();          }          return false;      }  

更多相关文章

  1. sd卡相关
  2. Android(安卓)Studio 获取数字签名信息(SHA1)
  3. [整理]android中几种常见的尺寸
  4. android有用代码片段
  5. Android(安卓)获取前台应用
  6. Android之获取手机相关信息
  7. Android中 Bitmap和Drawable相互转换的方法
  8. Android(安卓)Dialog 使用 ConstraintLayout 约束布局宽度异常原
  9. Android获取声音长度

随机推荐

  1. Flutter 透明状态栏及字体颜色的设置方法
  2. Android输入法遮挡问题的解决思路
  3. Android几种FrameWork(Manager)的用法
  4. MixtureTextView 支持Android图文混排、
  5. android : 如何通过provider向外共享数据
  6. Android(安卓)远程回调
  7. Eclipse,到了说再见的时候了——Android(
  8. Many PC buyers are still untapped pote
  9. 高德Demo,网上找了很多资料都不适合,自己研
  10. android 调用系统计算器 实例