ToolUtils

直接上代碼

package com.xxx.utils;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.graphics.BitmapFactory;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import com.ktc.base.SczwApplication;
import com.ktc.sczwdemo.R;

/**
 * @Date 2016-5-15 下午3:27:07
 * @Author Arvin
 * @Description 工具類
 */ 
public class ToolUtils {
    private static final String TAG = ToolUtils.class.getSimpleName();
    
    public static Context getContext() {
        return SczwApplication.getContext();
    }

    /**
     * 得到Resource對象
     */
    public static Resources getResources() {
        return getContext().getResources();
    }

    /**
     * @Description 獲得應(yīng)用的包名
     * @param null
     * @return String
     * @throws
     */
    public static String getPackageName() {
        return getContext().getPackageName();
    }
    
    /**
     * @Description 格式化空間大小
     * @param double
     * @return String
     * @throws
     */  
    public static String getFormatSize(double size) {  
        double kiloByte = size / 1024;  
        if (kiloByte < 1) {  
            return size + "B";  
        }  
  
        double megaByte = kiloByte / 1024;  
        if (megaByte < 1) {  
            BigDecimal result1 = new BigDecimal(Double.toString(kiloByte));  
            return result1.setScale(2, BigDecimal.ROUND_HALF_UP)  
                    .toPlainString() + "KB";  
        }  
  
        double gigaByte = megaByte / 1024;  
        if (gigaByte < 1) {  
            BigDecimal result2 = new BigDecimal(Double.toString(megaByte));  
            return result2.setScale(2, BigDecimal.ROUND_HALF_UP)  
                    .toPlainString() + "MB";  
        }  
  
        double teraBytes = gigaByte / 1024;  
        if (teraBytes < 1) {  
            BigDecimal result3 = new BigDecimal(Double.toString(gigaByte));  
            return result3.setScale(2, BigDecimal.ROUND_HALF_UP)  
                    .toPlainString() + "GB";  
        }  
        BigDecimal result4 = new BigDecimal(teraBytes);  
        return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString()  
                + "TB";  
    }  
      
    /**
     * @Description 獲取緩存空間cache大小
     * @param null
     * @return String
     * @throws Exception
     */  
    public static String getCacheSize() throws Exception {  
        return getFormatSize(getFolderSize(getContext().getExternalCacheDir()));  
    } 
    /**
     * @Description 獲取cache路徑空間大小
     * @param File
     * @return long
     * @throws Exception
     */ 
    public static long getFolderSize(File file) throws Exception {  
        long size = 0;  
        try {  
            File[] fileList = file.listFiles();  
            for (int i = 0; i < fileList.length; i++) {  
                if (fileList[i].isDirectory()) {  
                    size = size + getFolderSize(fileList[i]);  
                } else {  
                    size = size + fileList[i].length();  
                }  
            }  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        return size;  
    }  
   
    /**
     * @Description 清除應(yīng)用緩存,即刪除data/data/packageName/cache目錄下文件
     * @param null
     * @return null
     * @throws
     */
    public static void clearCache(){
        (new Thread(){
            @Override
            public void run() {
                try {
                    File path = getContext().getCacheDir();
                    if(path ==null)
                    return;
                    String killer =" rm -r " + path.toString();
                    Process p = Runtime.getRuntime().exec("su");
                    DataOutputStream os =new DataOutputStream(p.getOutputStream());
                    os.writeBytes(killer.toString() +"\n");
                    os.writeBytes("exit\n");
                    os.flush();
                } catch (IOException e) {
                    //TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }).start();
    }
    
    /**
     * @Description 獲取屏幕大小
     * @param null
     * @return int
     * @throws
     */
    public static Screen getScreenPix() {
        DisplayMetrics dm = new DisplayMetrics();
        WindowManager windowManager = (WindowManager) getContext()
                .getSystemService(Context.WINDOW_SERVICE);
        windowManager.getDefaultDisplay().getMetrics(dm);
        return new Screen(dm.widthPixels, dm.heightPixels);
    }

    /**
     * @Description 獲取屏幕寬度
     * @param null
     * @return int
     * @throws
     */
    public static int getScreenWidthPix() {
        DisplayMetrics dm = new DisplayMetrics();
        WindowManager windowManager = (WindowManager) getContext()
                .getSystemService(Context.WINDOW_SERVICE);
        windowManager.getDefaultDisplay().getMetrics(dm);
        return new Screen(dm.widthPixels, dm.heightPixels).widthPixels;
    }

    /**
     * @Description 獲取屏幕高度
     * @param null
     * @return int
     * @throws
     */
    public static int getScreenHeightPix() {
        DisplayMetrics dm = new DisplayMetrics();
        WindowManager windowManager = (WindowManager) getContext()
                .getSystemService(Context.WINDOW_SERVICE);
        windowManager.getDefaultDisplay().getMetrics(dm);
        return new Screen(dm.widthPixels, dm.heightPixels).heightPixels;
    }
    
    /**
     * @Description 定義一個screen類型
     * @param tags
     * @return return_type
     * @throws
     */
    public static class Screen {
        public int widthPixels;
        public int heightPixels;

        public Screen() {
        }

        public Screen(int widthPixels, int heightPixels) {
            this.widthPixels = widthPixels;
            this.heightPixels = heightPixels;
        }

        @Override
        public String toString() {
            return "(" + widthPixels + "," + heightPixels + ")";
        }
    }
    
    /**
     * @Description 判斷注冊郵箱是否填寫規(guī)范
     * @param String
     * @return boolean
     * @throws
     */
    public static boolean emailFormat(String email) {
        boolean tag = true;
        final String pattern1 = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
        final Pattern pattern = Pattern.compile(pattern1);
        final Matcher mat = pattern.matcher(email);
        if (!mat.find()) {
            tag = false;
        }
        return tag;
    }

    /**
     * @Description 判斷是否存在SDcard
     * @param null
     * @return boolean
     * @throws
     */
    public static boolean hasSdcard() {
        String state = Environment.getExternalStorageState();
        if (state.equals(Environment.MEDIA_MOUNTED)) {
            return true;
        } else {
            return false;
        }
    }
    
    /**
     * @Description 定義Toast(string)
     * @param int
     * @return null
     * @throws
     */
    public static void showToast(String msg) {
        Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show();
    }
    
    /**
     * @Description 定義Toast(id)
     * @param int
     * @return null
     * @throws
     */
    public static void showToast(int msg) {
        Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show();
    }
    
    /**
     * @Description  驗證字符串是否為空 或 ""
     * @param int
     * @return null
     * @throws
     */
    public static boolean validateString(String str) {
        if (str != null && !"".equals(str.trim()))
            return false;
        return true;
    }
    
    /**
     * @Description 獲得渠道號(推廣平臺0=本站,1=安智,2=機鋒,3=安卓官方)
     * @param null
     * @return String
     * @throws
     */
    public static String getChannelCode() {
        String channelCode = "0";
        try {
            ApplicationInfo ai = getContext().getPackageManager()
                    .getApplicationInfo(getContext().getPackageName(),
                            PackageManager.GET_META_DATA);
            Bundle bundle = ai.metaData;
            if (bundle != null) {

                Object obj = bundle.get("UMENG_CHANNEL");
                if (obj != null) {
                    channelCode = obj.toString();
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return channelCode;
    }

    /**
     * @Description 檢查網(wǎng)絡(luò)是否可用
     * @param null
     * @return boolean
     * @throws
     */
    public static boolean isConnect() {
        // 獲取手機所有連接管理對象(包括對wi-fi,net等連接的管理)
        try {
            ConnectivityManager connectivity = (ConnectivityManager) getContext()
                    .getSystemService(Context.CONNECTIVITY_SERVICE);
            if (connectivity != null) {
                // 獲取網(wǎng)絡(luò)連接管理的對象
                NetworkInfo info = connectivity.getActiveNetworkInfo();
                if (info != null && info.isConnected()) {
                    // 判斷當前網(wǎng)絡(luò)是否已經(jīng)連接
                    if (info.getState() == NetworkInfo.State.CONNECTED) {
                        return true;
                    }
                }
            }
        } catch (Exception e) {
            Log.v("error", e.toString());
        }
        return false;
    }

    /**
     * @Description 對圖片的大小進行判斷绒疗,并得到合適的縮放比例驹尼,比如2即1/2,3即1/3
     * @param BitmapFactory.Options options,int minSideLength, int maxNumOfPixels
     * @return int
     * @throws
     */
    public static int computeSampleSize(BitmapFactory.Options options,
            int minSideLength, int maxNumOfPixels) {
        int initialSize = computeInitialSampleSize(options, minSideLength,
                maxNumOfPixels);

        int roundedSize;
        if (initialSize <= 8) {
            roundedSize = 1;
            while (roundedSize < initialSize) {
                roundedSize <<= 1;
            }
        } else {
            roundedSize = (initialSize + 7) / 8 * 8;
        }
        return roundedSize;
    }

    private static int computeInitialSampleSize(BitmapFactory.Options options,
            int minSideLength, int maxNumOfPixels) {
        double w = options.outWidth;
        double h = options.outHeight;

        int lowerBound = (maxNumOfPixels == -1) ? 1 : (int) Math.ceil(Math
                .sqrt(w * h / maxNumOfPixels));
        int upperBound = (minSideLength == -1) ? 80 : (int) Math.min(
                Math.floor(w / minSideLength), Math.floor(h / minSideLength));

        if (upperBound < lowerBound) {
            // return the larger one when there is no overlapping zone.
            return lowerBound;
        }

        if ((maxNumOfPixels == -1) && (minSideLength == -1)) {
            return 1;
        } else if (minSideLength == -1) {
            return lowerBound;
        } else {
            return upperBound;
        }
    }
    
    /**
     * @Description MD5加密
     * @param String
     * @return String
     * @throws
     */
    public static String encryption(String enc) {
        String md5 = null;
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            byte[] bs = enc.getBytes();
            digest.update(bs);
            md5 = byte2hex(digest.digest());
            Log.i("md5", md5);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return md5;
    }

    private static String byte2hex(byte[] b) {
        String hs = "";
        String stmp = "";
        for (int n = 0; n < b.length; n++) {
            stmp = (java.lang.Integer.toHexString(b[n] & 0xFF));
            if (stmp.length() == 1)
                hs = hs + "0" + stmp;
            else
                hs = hs + stmp;
        }
        return hs;
    }
    
    /**
     * @Description 以md5方式加密字符串
     * @param 默認32位長度
     * @return String
     * @throws
     */
    public static String getMd5() {
        try {
            String content = Constants.MD5_HEAD+getIMEI();
            MessageDigest bmd5 = MessageDigest.getInstance("MD5");
            bmd5.update(content.getBytes());
            int i;
            StringBuffer buf = new StringBuffer();
            byte[] b = bmd5.digest();
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0)
                    i += 256;
                if (i < 16)
                    buf.append("0");
                buf.append(Integer.toHexString(i));
            }
            return buf.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }
    
    /**
     * @Description 以md5方式加密字符串;返回的長度,支持16位和32位,例length=16,length=32
     * @param String
     * @return String
     * @throws
     */
    public static String getMd5(String content, int length) {
        try {
            MessageDigest bmd5 = MessageDigest.getInstance("MD5");
            bmd5.update(content.getBytes());
            int i;
            StringBuffer buf = new StringBuffer();
            byte[] b = bmd5.digest();
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0)
                    i += 256;
                if (i < 16)
                    buf.append("0");
                buf.append(Integer.toHexString(i));
            }
            String md5Content = buf.toString();
            switch (length) {
            case 16:
                md5Content = md5Content.substring(0, 16);
                break;
            case 32:
            default:
                break;
            }
            return md5Content;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }

    public ByteArrayOutputStream getByteArrayOutputStreamByInputStream(
            InputStream inputStream) throws Exception {

        byte[] buffer = new byte[1024];
        int len = -1;
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        while ((len = inputStream.read(buffer)) != -1) {
            byteArrayOutputStream.write(buffer, 0, len);
        }
        return byteArrayOutputStream;
    }
    
    /**
     * @Description 切換白天和夜間模式
     * @param Window 當前的Window窗體振湾;boolean是否是夜間模式
     * @return null
     * @throws
     */
    public void setScreenBrightness(Window window, boolean isNightModel) {
        WindowManager.LayoutParams lp = window.getAttributes();
        if (isNightModel) {
            lp.screenBrightness = 0.4f;
        } else {
            lp.screenBrightness = 1.0f;
        }
        window.setAttributes(lp);
    }
    
    /**
     * @Description 獲取當前日期
     * @param null
     * @return String:2016-05-13
     * @throws
     */
    public static String getCurrentDate() {
        final Calendar c = Calendar.getInstance();
        int mYear = c.get(Calendar.YEAR); 
        int mMonth = c.get(Calendar.MONTH);
        int mDay = c.get(Calendar.DAY_OF_MONTH);
        return mYear + "-" + mMonth + "-" + mDay;
    }
    
    /**
     * @Description 獲取6位隨機數(shù)字
     * @param null
     * @return int
     * @throws
     */
    public static int getSixNum() {
        int numcode = (int) ((Math.random() * 9 + 1) * 100000);
        return numcode;
    }
    
    
    public static String getNumberFromString(String str) {
        String str2 = "";
        if (str != null && !"".equals(str)) {
            for (int i = 0; i < str.length(); i++) {
                if (str.charAt(i) >= 48 && str.charAt(i) <= 57) {
                    str2 += str.charAt(i);
                }
            }
        }
        return str2;
    }

    /**
     * @Description 判斷網(wǎng)絡(luò)狀態(tài)
     * @param null
     * @return boolean
     * @throws
     */
    public static boolean checkNet() {
        ConnectivityManager manager = (ConnectivityManager) getContext()
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = manager.getActiveNetworkInfo();
        if (info != null) {
            return true;
        }
        return false;
    }

    public static String getAPN() {
        String apn = "";
        ConnectivityManager manager = (ConnectivityManager) getContext()
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = manager.getActiveNetworkInfo();

        if (info != null) {
            if (ConnectivityManager.TYPE_WIFI == info.getType()) {
                apn = info.getTypeName();
                if (apn == null) {
                    apn = "wifi";
                }
            } else {
                apn = info.getExtraInfo().toLowerCase();
                if (apn == null) {
                    apn = "mobile";
                }
            }
        }
        return apn;
    }

    public static String getModel() {
        return Build.MODEL;
    }

    public static String getManufacturer() {
        return Build.MANUFACTURER;
    }

    public static String getFirmware() {
        return Build.VERSION.RELEASE;
    }

    /**
     * @Description 獲取設(shè)備SDK版本號
     * @param null
     * @return String
     * @throws
     */
    public static String getSDKVer() {
        return Integer.valueOf(Build.VERSION.SDK_INT).toString();
    }

    /**
     * @Description 獲取當前語言類型
     * @param null
     * @return String
     * @throws
     */
    public static String getLanguage() {
        Locale locale = Locale.getDefault();
        String languageCode = locale.getLanguage();
        if (TextUtils.isEmpty(languageCode)) {
            languageCode = "";
        }
        return languageCode;
    }

    /**
     * @Description 獲取當前國家碼
     * @param null
     * @return String
     * @throws
     */
    public static String getCountry() {
        Locale locale = Locale.getDefault();
        String countryCode = locale.getCountry();
        if (TextUtils.isEmpty(countryCode)) {
            countryCode = "";
        }
        return countryCode;
    }

    /**
     * @Description 獲取IMEI號碼
     * @param null
     * @return String
     * @throws
     */
    public static String getIMEI() {
        TelephonyManager mTelephonyMgr = (TelephonyManager) getContext()
                .getSystemService(Context.TELEPHONY_SERVICE);
        String imei = mTelephonyMgr.getDeviceId();
        if (TextUtils.isEmpty(imei) || imei.equals("000000000000000")) {
            imei = "0";
        }

        return imei;
    }

    /**
     * @Description 獲取到客戶ID歌懒,即IMSI
     * @param null
     * @return String
     * @throws
     */
    public static String getIMSI() {
        TelephonyManager mTelephonyMgr = (TelephonyManager) getContext()
                .getSystemService(Context.TELEPHONY_SERVICE);
        String imsi = mTelephonyMgr.getSubscriberId();
        if (TextUtils.isEmpty(imsi)) {
            return "0";
        } else {
            return imsi;
        }
    }


    /**
     * @Description 獲取本機手機號
     * @param null
     * @return String
     * @throws
     */
    public static String getLine1Number(){
        TelephonyManager telephonyManager=(TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
        String imei=telephonyManager.getLine1Number();
        return imei;
    }

    /**
     * @Description 獲取網(wǎng)絡(luò)運營商代號
     * @param null
     * @return String
     * @throws
     */
    public static String getMcnc() {

        TelephonyManager tm = (TelephonyManager) getContext()
                .getSystemService(Context.TELEPHONY_SERVICE);
        String mcnc = tm.getNetworkOperator();
        if (TextUtils.isEmpty(mcnc)) {
            return "0";
        } else {
            return mcnc;
        }
    }

    /**
     * @Description 獲取手機的sdk版本號
     * @param null
     * @return int
     * @throws
     */
    public static int getPhoneSDK() {
        TelephonyManager phoneMgr = (TelephonyManager) getContext()
                .getSystemService(Context.TELEPHONY_SERVICE);
        Logger.i(TAG, "Bild model:" + Build.MODEL);
        Logger.i(TAG, "Phone Number:" + phoneMgr.getLine1Number());
        Logger.i(TAG, "SDK VERSION:" + Build.VERSION.SDK);
        Logger.i(TAG, "SDK RELEASE:" + Build.VERSION.RELEASE);
        int sdk = 7;
        try {
            sdk = Integer.parseInt(Build.VERSION.SDK);
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
        return sdk;
    }

    public static Object getMetaData(String keyName) {
        try {
            ApplicationInfo info = getContext().getPackageManager()
                    .getApplicationInfo(getContext().getPackageName(),
                            PackageManager.GET_META_DATA);

            Bundle bundle = info.metaData;
            Object value = bundle.get(keyName);
            return value;
        } catch (NameNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return "";
    }

    /**
     * @Description 獲取應(yīng)用版本信息
     * @param null
     * @return String
     * @throws
     */
    public static String getAppVersion() {
        PackageManager pm = getContext().getPackageManager();
        PackageInfo pi;
        try {
            pi = pm.getPackageInfo(getContext().getPackageName(), 0);
            String versionName = pi.versionName;
            return versionName;
        } catch (NameNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return "";
    }

    /**
     * 判斷SDCard是否已滿
     * 
     * @return
     */
    public static boolean isSDCardSizeOverflow() {
        boolean result = false;
        // 取得SDCard當前的狀態(tài)
        String sDcString = android.os.Environment.getExternalStorageState();

        if (sDcString.equals(android.os.Environment.MEDIA_MOUNTED)) {

            // 取得sdcard文件路徑
            File pathFile = android.os.Environment
                    .getExternalStorageDirectory();
            android.os.StatFs statfs = new android.os.StatFs(pathFile.getPath());

            // 獲取SDCard上BLOCK總數(shù)
            long nTotalBlocks = statfs.getBlockCount();

            // 獲取SDCard上每個block的SIZE
            long nBlocSize = statfs.getBlockSize();

            // 獲取可供程序使用的Block的數(shù)量
            long nAvailaBlock = statfs.getAvailableBlocks();

            // 獲取剩下的所有Block的數(shù)量(包括預(yù)留的一般程序無法使用的塊)
            long nFreeBlock = statfs.getFreeBlocks();

            // 計算SDCard 總?cè)萘看笮B
            long nSDTotalSize = nTotalBlocks * nBlocSize / 1024 / 1024;

            // 計算 SDCard 剩余大小MB
            long nSDFreeSize = nAvailaBlock * nBlocSize / 1024 / 1024;
            if (nSDFreeSize <= 1) {
                result = true;
            }
        }// end of if
            // end of func
        return result;
    }
    
    /**
     * @Description 格式化時間
     * @param Long
     * @return String
     * @throws
     */
   public static String getFomatTime(Long time){
        SimpleDateFormat format=new SimpleDateFormat(ResUtils.getString(R.string.time_format));  
        Date date = new Date(time);  
        String time_str = format.format(date);
        return time_str; 
   }
    
   
   /**
 * @Description 判斷字符串是否是郵箱格式
 * @param String
 * @return Boolean
 * @throws
 */
    public static boolean checkEmail(String str) {
        Boolean isEmail = false;
        String expr = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
        if (str.matches(expr)) {
            isEmail = true;
        }
        return isEmail;
    }

     /**
     * @Description 判斷字符串是否是銀行卡號
     * @param String
     * @return Boolean
     * @throws
     */
  public static boolean checkBankCard(String cardId) {  
      char bit = getBankCardCheckCode(cardId  
              .substring(0, cardId.length() - 1));  
      if (bit == 'N') {  
          return false;  
      }  
      return cardId.charAt(cardId.length() - 1) == bit;  

  }  
  
  private static char getBankCardCheckCode(String nonCheckCodeCardId) {  
      if (nonCheckCodeCardId == null  
              || nonCheckCodeCardId.trim().length() == 0  
              || !nonCheckCodeCardId.matches("\\d+")) {  
          // 如果傳的不是數(shù)據(jù)返回N  
          return 'N';  
      }  
      char[] chs = nonCheckCodeCardId.trim().toCharArray();  
      int luhmSum = 0;  
      for (int i = chs.length - 1, j = 0; i >= 0; i--, j++) {  
          int k = chs[i] - '0';  
          if (j % 2 == 0) {  
              k *= 2;  
              k = k / 10 + k % 10;  
          }  
          luhmSum += k;  
      }  
      return (luhmSum % 10 == 0) ? '0' : (char) ((10 - luhmSum % 10) + '0');  
  }

  /**
   * @Description 判斷字符串是否是手機號
   * @param String
   * @return Boolean
   * @throws
   */
  public static boolean checkPhone(String phone) {  
      Pattern pattern = Pattern  
              .compile("^(13[0-9]|15[0-9]|153|15[6-9]|180|18[23]|18[5-9])\\d{8}$");  
      Matcher matcher = pattern.matcher(phone);  

      if (matcher.matches()) {  
          return true;  
      }  
      return false;  
  }
  
  /**
 * @Description 在指定文件夾中創(chuàng)建文件
 * @param tags
 * @return return_type
 * @throws
 */
   public static void makeNewFile(String filePath){
       if(hasSdcard()&&!isSDCardSizeOverflow()){
             File sdcardDir =Environment.getExternalStorageDirectory();
             String rootPath = sdcardDir.getPath()+"/SCZW";
             File file = new File(rootPath);
            if (!file.exists()) {
                 file.mkdirs();
            }
            //創(chuàng)建文件
            File newFile = new File(rootPath+"/"+filePath);
            if (!newFile.exists()) {
                try {
                    newFile.createNewFile();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
           }
      }
  }
   
}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市卷哩,隨后出現(xiàn)的幾起案子舱禽,更是在濱河造成了極大的恐慌琉历,老刑警劉巖,帶你破解...
    沈念sama閱讀 222,729評論 6 517
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件见转,死亡現(xiàn)場離奇詭異命雀,居然都是意外死亡,警方通過查閱死者的電腦和手機斩箫,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,226評論 3 399
  • 文/潘曉璐 我一進店門吏砂,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人校焦,你說我怎么就攤上這事赊抖。” “怎么了寨典?”我有些...
    開封第一講書人閱讀 169,461評論 0 362
  • 文/不壞的土叔 我叫張陵氛雪,是天一觀的道長。 經(jīng)常有香客問我耸成,道長报亩,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 60,135評論 1 300
  • 正文 為了忘掉前任井氢,我火速辦了婚禮弦追,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘花竞。我一直安慰自己劲件,他們只是感情好,可當我...
    茶點故事閱讀 69,130評論 6 398
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著零远,像睡著了一般苗分。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上牵辣,一...
    開封第一講書人閱讀 52,736評論 1 312
  • 那天摔癣,我揣著相機與錄音,去河邊找鬼纬向。 笑死择浊,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的逾条。 我是一名探鬼主播琢岩,決...
    沈念sama閱讀 41,179評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼膳帕!你這毒婦竟也來了粘捎?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 40,124評論 0 277
  • 序言:老撾萬榮一對情侶失蹤危彩,失蹤者是張志新(化名)和其女友劉穎攒磨,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體汤徽,經(jīng)...
    沈念sama閱讀 46,657評論 1 320
  • 正文 獨居荒郊野嶺守林人離奇死亡娩缰,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,723評論 3 342
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了谒府。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片拼坎。...
    茶點故事閱讀 40,872評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖完疫,靈堂內(nèi)的尸體忽然破棺而出泰鸡,到底是詐尸還是另有隱情,我是刑警寧澤壳鹤,帶...
    沈念sama閱讀 36,533評論 5 351
  • 正文 年R本政府宣布盛龄,位于F島的核電站,受9級特大地震影響芳誓,放射性物質(zhì)發(fā)生泄漏余舶。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 42,213評論 3 336
  • 文/蒙蒙 一锹淌、第九天 我趴在偏房一處隱蔽的房頂上張望匿值。 院中可真熱鬧,春花似錦赂摆、人聲如沸挟憔。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,700評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽绊谭。三九已至厘唾,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間龙誊,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,819評論 1 274
  • 我被黑心中介騙來泰國打工喷楣, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留趟大,地道東北人。 一個月前我還...
    沈念sama閱讀 49,304評論 3 379
  • 正文 我出身青樓铣焊,卻偏偏與公主長得像逊朽,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子曲伊,可洞房花燭夜當晚...
    茶點故事閱讀 45,876評論 2 361

推薦閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,332評論 25 707
  • ¥開啟¥ 【iAPP實現(xiàn)進入界面執(zhí)行逐一顯】 〖2017-08-25 15:22:14〗 《//首先開一個線程叽讳,因...
    小菜c閱讀 6,451評論 0 17
  • 我們想要活出自己,就必須得走出圍欄坟募。這是我看完《橙沙之味》這部電影最深的感觸岛蚤。 影片一開始就是千太郎的滿面愁容,無...
    吃火鍋嗎閱讀 295評論 0 0
  • 今天風和日麗懈糯,天氣正好涤妒,我終于身臨其境的感受了一下落地窗外差異化的風光,似乎來到了市區(qū)的城鄉(xiāng)結(jié)合部赚哗,頓時百感交集她紫!...
    吾淚閱讀 390評論 0 0