示例#1
1
 /**
  * Deposit in the province read images, width is high, the greater the picture clearer, but also
  * the memory
  *
  * @param imagePath Pictures in the path of the memory card
  * @param maxWidth The highest limit value target width
  * @param maxHeight The highest limit value target height
  * @return
  */
 public Bitmap readImage(String imagePath, int maxWidth, int maxHeight) {
   File imageFile = new File(imagePath);
   if (imageFile.exists()) {
     try {
       BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(imageFile));
       BitmapFactory.Options options = new BitmapFactory.Options();
       options.inJustDecodeBounds = true;
       BitmapFactory.decodeStream(inputStream, null, options);
       inputStream.close();
       int i = 0;
       while (true) {
         if ((options.outWidth >> i <= maxWidth) && (options.outHeight >> i <= maxHeight)) {
           inputStream = new BufferedInputStream(new FileInputStream(new File(imagePath)));
           options.inSampleSize = (int) Math.pow(2.0, i);
           options.inJustDecodeBounds = false;
           Bitmap bitmap = BitmapFactory.decodeStream(inputStream, null, options);
           inputStream.close();
           return bitmap;
         }
         i += 1;
       }
     } catch (IOException e) {
       Logger.e("This path does not exist" + imagePath, e);
     }
   }
   return null;
 }
示例#2
0
 /**
  * Check the netwoek is enable
  *
  * @param context Access to {@code ConnectivityManager} services
  * @return Available returns true, unavailable returns false
  */
 @SuppressWarnings("deprecation")
 @SuppressLint("NewApi")
 public static boolean isNetworkAvailable(Context context) {
   try {
     ConnectivityManager connectivity =
         (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
     if (connectivity == null) {
       return false;
     } else {
       if (VERSION.SDK_INT >= 21) {
         Network[] networks = connectivity.getAllNetworks();
         for (Network network : networks) {
           NetworkInfo networkInfo = connectivity.getNetworkInfo(network);
           if (networkInfo.getState() == NetworkInfo.State.CONNECTED) return true;
         }
       } else {
         NetworkInfo[] networkInfos = connectivity.getAllNetworkInfo();
         for (NetworkInfo networkInfo : networkInfos)
           if (networkInfo.getState() == NetworkInfo.State.CONNECTED) return true;
       }
     }
   } catch (Throwable e) {
     Logger.throwable(e);
   }
   return false;
 }
 @Override
 public void onSucceed(int what, Response<Bitmap> response) {
   Bitmap bitmap = response.get();
   if (bitmap == null) Logger.i("图片非空");
   mImageView.setImageBitmap(bitmap);
   mStatus.setText("成功");
 }
示例#4
0
 /**
  * Open or close the GPRS
  *
  * @param context Access to {@code ConnectivityManager} services
  * @param isEnable Open to true, close to false
  */
 public static void setGPRSEnable(Context context, boolean isEnable) {
   try {
     ConnectivityManager connectivityManager =
         (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
     Class<?> cmClass = connectivityManager.getClass();
     Class<?>[] argClasses = new Class[1];
     argClasses[0] = boolean.class;
     Method method = cmClass.getMethod("setMobileDataEnabled", argClasses);
     method.invoke(connectivityManager, isEnable);
   } catch (Throwable e) {
     Logger.throwable(e);
   }
 }
示例#5
0
 /**
  * Check the GPRS whether available
  *
  * @param context Access to {@code ConnectivityManager} services
  * @return Open return true, close returns false
  */
 public static boolean isGPRSOpen(Context context) {
   Boolean isOpen = false;
   try {
     ConnectivityManager connectivityManager =
         (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
     Class<?> cmClass = connectivityManager.getClass();
     Class<?>[] argClasses = null;
     Method method = cmClass.getMethod("getMobileDataEnabled", argClasses);
     Object[] argObject = null;
     isOpen = (Boolean) method.invoke(connectivityManager, argObject);
   } catch (Throwable e) {
     Logger.throwable(e);
   }
   return isOpen;
 }
示例#6
0
 /**
  * Tet local ip adress
  *
  * @return Such as:192.168.1.1
  */
 public static String getLocalIPAddress() {
   String ipAddress = "";
   try {
     Enumeration<NetworkInterface> netfaces = NetworkInterface.getNetworkInterfaces();
     // 遍历所用的网络接口
     while (netfaces.hasMoreElements()) {
       NetworkInterface nif = netfaces.nextElement(); // 得到每一个网络接口绑定的地址
       Enumeration<InetAddress> inetAddresses = nif.getInetAddresses();
       // 遍历每一个接口绑定的所有ip
       while (inetAddresses.hasMoreElements()) {
         InetAddress ip = inetAddresses.nextElement();
         if (!ip.isLoopbackAddress() && isIPv4Address(ip.getHostAddress())) {
           ipAddress = ip.getHostAddress();
         }
       }
     }
   } catch (Throwable e) {
     Logger.throwable(e);
   }
   return ipAddress;
 }