Android常用代碼集

1、撥打電話

public static void call(Context context, String phoneNumber) {

?context.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber)));

}

需要添加權(quán)限

2这难、跳轉(zhuǎn)至撥號界面

public static void callDial(Context context, String phoneNumber) {

context.startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phoneNumber)));

}

3舟误、發(fā)送短信

public static void sendSms(Context context, String phoneNumber,

String content) {

Uri uri = Uri.parse("smsto:"

+ (TextUtils.isEmpty(phoneNumber) ? "" : phoneNumber));

Intent intent = new Intent(Intent.ACTION_SENDTO, uri);

intent.putExtra("sms_body", TextUtils.isEmpty(content) ? "" : content);

context.startActivity(intent);

}

5、喚醒屏幕并解鎖

public static void wakeUpAndUnlock(Context context){

KeyguardManager km= (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);

KeyguardManager.KeyguardLock kl = km.newKeyguardLock("unLock");

//解鎖

kl.disableKeyguard();

//獲取電源管理器對象

PowerManager pm=(PowerManager) context.getSystemService(Context.POWER_SERVICE);

//獲取PowerManager.WakeLock對象,后面的參數(shù)|表示同時傳入兩個值,最后的是LogCat里用的Tag

PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | ? ? ? ? ?PowerManager.SCREEN_DIM_WAKE_LOCK,"bright");

//點亮屏幕

wl.acquire();

//釋放

wl.release();

}

需要添加權(quán)限

6姻乓、判斷當前App處于前臺還是后臺狀態(tài)

public static boolean isApplicationBackground(final Context context) {

ActivityManager am = (ActivityManager) context

.getSystemService(Context.ACTIVITY_SERVICE);

@SuppressWarnings("deprecation")

List tasks = am.getRunningTasks(1);

if (!tasks.isEmpty()) {

ComponentName topActivity = tasks.get(0).topActivity;

if (!topActivity.getPackageName().equals(context.getPackageName())) {

return true;

}

}

return false;

}

需要添加權(quán)限

android:name="android.permission.GET_TASKS" />

7嵌溢、判斷當前手機是否處于鎖屏(睡眠)狀態(tài)

public static boolean isSleeping(Context context) {

KeyguardManager kgMgr = (KeyguardManager) context

.getSystemService(Context.KEYGUARD_SERVICE);

boolean isSleeping = kgMgr.inKeyguardRestrictedInputMode();

return isSleeping;

}

8眯牧、判斷當前是否有網(wǎng)絡(luò)連接

public static boolean isOnline(Context context) {

ConnectivityManager manager = (ConnectivityManager) context

.getSystemService(Activity.CONNECTIVITY_SERVICE);

NetworkInfo info = manager.getActiveNetworkInfo();

if (info != null && info.isConnected()) {

return true;

}

return false;

}

9、判斷當前是否是WIFI連接狀態(tài)

public static boolean isWifiConnected(Context context) {

ConnectivityManager connectivityManager = (ConnectivityManager) context

.getSystemService(Context.CONNECTIVITY_SERVICE);

NetworkInfo wifiNetworkInfo = connectivityManager

.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

if (wifiNetworkInfo.isConnected()) {

return true;

}

return false;

}

10赖草、安裝APK

public static void installApk(Context context, File file) {

Intent intent = new Intent();

intent.setAction("android.intent.action.VIEW");

intent.addCategory("android.intent.category.DEFAULT");

intent.setType("application/vnd.android.package-archive");

intent.setDataAndType(Uri.fromFile(file),

"application/vnd.android.package-archive");

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

context.startActivity(intent);

}

11学少、判斷當前設(shè)備是否為手機

public static boolean isPhone(Context context) {

TelephonyManager telephony = (TelephonyManager) context

.getSystemService(Context.TELEPHONY_SERVICE);

if (telephony.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) {

return false;

} else {

return true;

}

}

12、獲取當前設(shè)備寬高秧骑,單位px

@SuppressWarnings("deprecation")

public static int getDeviceWidth(Context context) {

WindowManager manager = (WindowManager) context

.getSystemService(Context.WINDOW_SERVICE);

return manager.getDefaultDisplay().getWidth();

}

@SuppressWarnings("deprecation")

public static int getDeviceHeight(Context context) {

WindowManager manager = (WindowManager) context

.getSystemService(Context.WINDOW_SERVICE);

return manager.getDefaultDisplay().getHeight();

}

13版确、獲取當前設(shè)備的IMEI,需要與上面的isPhone()一起使用

@TargetApi(Build.VERSION_CODES.CUPCAKE)

public static String getDeviceIMEI(Context context) {

String deviceId;

if (isPhone(context)) {

TelephonyManager telephony = (TelephonyManager) context

.getSystemService(Context.TELEPHONY_SERVICE);

deviceId = telephony.getDeviceId();

} else {

deviceId = Settings.Secure.getString(context.getContentResolver(),

Settings.Secure.ANDROID_ID);

}

return deviceId;

}

14乎折、獲取當前設(shè)備的MAC地址

public static String getMacAddress(Context context) {

String macAddress;

WifiManager wifi = (WifiManager) context

.getSystemService(Context.WIFI_SERVICE);

WifiInfo info = wifi.getConnectionInfo();

macAddress = info.getMacAddress();

if (null == macAddress) {

return "";

}

macAddress = macAddress.replace(":", "");

return macAddress;

}

15绒疗、獲取當前程序的版本號

public static String getAppVersion(Context context) {

String version = "0";

try {

version = context.getPackageManager().getPackageInfo(

context.getPackageName(), 0).versionName;

} catch (PackageManager.NameNotFoundException e) {

e.printStackTrace();

}

return version;

}


1、收集設(shè)備信息骂澄,用于信息統(tǒng)計分析

public static Properties collectDeviceInfo(Context context) {

Properties mDeviceCrashInfo = new Properties();

try {

PackageManager pm = context.getPackageManager();

PackageInfo pi = pm.getPackageInfo(context.getPackageName(),

PackageManager.GET_ACTIVITIES);

if (pi != null) {

mDeviceCrashInfo.put(VERSION_NAME,

pi.versionName == null ? "not set" : pi.versionName);

mDeviceCrashInfo.put(VERSION_CODE, pi.versionCode);

}

} catch (PackageManager.NameNotFoundException e) {

Log.e(TAG, "Error while collect package info", e);

}

Field[] fields = Build.class.getDeclaredFields();

for (Field field : fields) {

try {

field.setAccessible(true);

mDeviceCrashInfo.put(field.getName(), field.get(null));

} catch (Exception e) {

Log.e(TAG, "Error while collect crash info", e);

}

}

return mDeviceCrashInfo;

}

public static String collectDeviceInfoStr(Context context) {

Properties prop = collectDeviceInfo(context);

Set deviceInfos = prop.keySet();

StringBuilder deviceInfoStr = new StringBuilder("{\n");

for (Iterator iter = deviceInfos.iterator(); iter.hasNext();) {

Object item = iter.next();

deviceInfoStr.append("\t\t\t" + item + ":" + prop.get(item)

+ ", \n");

}

deviceInfoStr.append("}");

return deviceInfoStr.toString();

}

2吓蘑、是否有SD卡

public static boolean haveSDCard() {

return android.os.Environment.getExternalStorageState().equals(

android.os.Environment.MEDIA_MOUNTED);

}

3、動態(tài)隱藏軟鍵盤

@TargetApi(Build.VERSION_CODES.CUPCAKE)

public static void hideSoftInput(Activity activity) {

View view = activity.getWindow().peekDecorView();

if (view != null) {

InputMethodManager inputmanger = (InputMethodManager) activity

.getSystemService(Context.INPUT_METHOD_SERVICE);

inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0);

}

}

@TargetApi(Build.VERSION_CODES.CUPCAKE)

public static void hideSoftInput(Context context, EditText edit) {

edit.clearFocus();

InputMethodManager inputmanger = (InputMethodManager) context

.getSystemService(Context.INPUT_METHOD_SERVICE);

inputmanger.hideSoftInputFromWindow(edit.getWindowToken(), 0);

}

4坟冲、動態(tài)顯示軟鍵盤

@TargetApi(Build.VERSION_CODES.CUPCAKE)

public static void showSoftInput(Context context, EditText edit) {

edit.setFocusable(true);

edit.setFocusableInTouchMode(true);

edit.requestFocus();

InputMethodManager inputManager = (InputMethodManager) context

.getSystemService(Context.INPUT_METHOD_SERVICE);

inputManager.showSoftInput(edit, 0);

}

5磨镶、動態(tài)顯示或者是隱藏軟鍵盤

@TargetApi(Build.VERSION_CODES.CUPCAKE)

public static void toggleSoftInput(Context context, EditText edit) {

edit.setFocusable(true);

edit.setFocusableInTouchMode(true);

edit.requestFocus();

InputMethodManager inputManager = (InputMethodManager) context

.getSystemService(Context.INPUT_METHOD_SERVICE);

inputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

}

6、主動回到Home健提,后臺運行

public static void goHome(Context context) {

Intent mHomeIntent = new Intent(Intent.ACTION_MAIN);

mHomeIntent.addCategory(Intent.CATEGORY_HOME);

mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK

| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

context.startActivity(mHomeIntent);

}

7琳猫、獲取狀態(tài)欄高度

注意,要在onWindowFocusChanged中調(diào)用私痹,在onCreate中獲取高度為0

@TargetApi(Build.VERSION_CODES.CUPCAKE)

public static int getStatusBarHeight(Activity activity) {

Rect frame = new Rect();

activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);

return frame.top;

}

8脐嫂、獲取狀態(tài)欄高度+標題欄(ActionBar)高度

(注意,如果沒有ActionBar侄榴,那么獲取的高度將和上面的是一樣的雹锣,只有狀態(tài)欄的高度)

public static int getTopBarHeight(Activity activity) {

return activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT)

.getTop();

}

9网沾、獲取MCC+MNC代碼 (SIM卡運營商國家代碼和運營商網(wǎng)絡(luò)代碼)

僅當用戶已在網(wǎng)絡(luò)注冊時有效, CDMA 可能會無效(中國移動:46000 46002, 中國聯(lián)通:46001,中國電信:46003)

public static String getNetworkOperator(Context context) {

TelephonyManager telephonyManager = (TelephonyManager) context

.getSystemService(Context.TELEPHONY_SERVICE);

return telephonyManager.getNetworkOperator();

}

10癞蚕、返回移動網(wǎng)絡(luò)運營商的名字

(例:中國聯(lián)通、中國移動辉哥、中國電信) 僅當用戶已在網(wǎng)絡(luò)注冊時有效, CDMA 可能會無效)

public static String getNetworkOperatorName(Context context) {

TelephonyManager telephonyManager = (TelephonyManager) context

.getSystemService(Context.TELEPHONY_SERVICE);

return telephonyManager.getNetworkOperatorName();

}

11桦山、返回移動終端類型

PHONE_TYPE_NONE :0 手機制式未知

PHONE_TYPE_GSM :1 手機制式為GSM,移動和聯(lián)通

PHONE_TYPE_CDMA :2 手機制式為CDMA醋旦,電信

PHONE_TYPE_SIP:3

public static int getPhoneType(Context context) {

TelephonyManager telephonyManager = (TelephonyManager) context

.getSystemService(Context.TELEPHONY_SERVICE);

return telephonyManager.getPhoneType();

}

12恒水、判斷手機連接的網(wǎng)絡(luò)類型(2G,3G,4G)

聯(lián)通的3G為UMTS或HSDPA,移動和聯(lián)通的2G為GPRS或EGDE饲齐,電信的2G為CDMA钉凌,電信的3G為EVDO

public class Constants {

/**

* Unknown network class

*/

public static final int NETWORK_CLASS_UNKNOWN = 0;

/**

* wifi net work

*/

public static final int NETWORK_WIFI = 1;

/**

* "2G" networks

*/

public static final int NETWORK_CLASS_2_G = 2;

/**

* "3G" networks

*/

public static final int NETWORK_CLASS_3_G = 3;

/**

* "4G" networks

*/

public static final int NETWORK_CLASS_4_G = 4;

}

public static int getNetWorkClass(Context context) {

TelephonyManager telephonyManager = (TelephonyManager) context

.getSystemService(Context.TELEPHONY_SERVICE);

switch (telephonyManager.getNetworkType()) {

case TelephonyManager.NETWORK_TYPE_GPRS:

case TelephonyManager.NETWORK_TYPE_EDGE:

case TelephonyManager.NETWORK_TYPE_CDMA:

case TelephonyManager.NETWORK_TYPE_1xRTT:

case TelephonyManager.NETWORK_TYPE_IDEN:

return Constants.NETWORK_CLASS_2_G;

case TelephonyManager.NETWORK_TYPE_UMTS:

case TelephonyManager.NETWORK_TYPE_EVDO_0:

case TelephonyManager.NETWORK_TYPE_EVDO_A:

case TelephonyManager.NETWORK_TYPE_HSDPA:

case TelephonyManager.NETWORK_TYPE_HSUPA:

case TelephonyManager.NETWORK_TYPE_HSPA:

case TelephonyManager.NETWORK_TYPE_EVDO_B:

case TelephonyManager.NETWORK_TYPE_EHRPD:

case TelephonyManager.NETWORK_TYPE_HSPAP:

return Constants.NETWORK_CLASS_3_G;

case TelephonyManager.NETWORK_TYPE_LTE:

return Constants.NETWORK_CLASS_4_G;

default:

return Constants.NETWORK_CLASS_UNKNOWN;

}

}

13、判斷當前手機的網(wǎng)絡(luò)類型(WIFI還是2,3,4G)

需要用到上面的方法

public static int getNetWorkStatus(Context context) {

int netWorkType = Constants.NETWORK_CLASS_UNKNOWN;

ConnectivityManager connectivityManager = (ConnectivityManager) context

.getSystemService(Context.CONNECTIVITY_SERVICE);

NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();

if (networkInfo != null && networkInfo.isConnected()) {

int type = networkInfo.getType();

if (type == ConnectivityManager.TYPE_WIFI) {

netWorkType = Constants.NETWORK_WIFI;

} else if (type == ConnectivityManager.TYPE_MOBILE) {

netWorkType = getNetWorkClass(context);

}

}

return netWorkType;

}


1捂人、px-dp轉(zhuǎn)換

public static int dip2px(Context context, float dpValue) {

final float scale = context.getResources().getDisplayMetrics().density;

return (int) (dpValue * scale + 0.5f);

}

public static int px2dip(Context context, float pxValue) {

final float scale = context.getResources().getDisplayMetrics().density;

return (int) (pxValue / scale + 0.5f);

}

2御雕、px-sp轉(zhuǎn)換

public static int px2sp(Context context, float pxValue) {

final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;

return (int) (pxValue / fontScale + 0.5f);

}

public static int sp2px(Context context, float spValue) {

final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;

return (int) (spValue * fontScale + 0.5f);

}

3矢沿、把一個毫秒數(shù)轉(zhuǎn)化成時間字符串

格式為小時/分/秒/毫秒(如:24903600 –> 06小時55分03秒600毫秒)

/**

* @param millis

*? ? ? ? ? ? 要轉(zhuǎn)化的毫秒數(shù)。

* @param isWhole

*? ? ? ? ? ? 是否強制全部顯示小時/分/秒/毫秒酸纲。

* @param isFormat

*? ? ? ? ? ? 時間數(shù)字是否要格式化捣鲸,如果true:少位數(shù)前面補全;如果false:少位數(shù)前面不補全闽坡。

* @return 返回時間字符串:小時/分/秒/毫秒的格式(如:24903600 --> 06小時55分03秒600毫秒)栽惶。

*/

public static String millisToString(long millis, boolean isWhole,

boolean isFormat) {

String h = "";

String m = "";

String s = "";

String mi = "";

if (isWhole) {

h = isFormat ? "00小時" : "0小時";

m = isFormat ? "00分" : "0分";

s = isFormat ? "00秒" : "0秒";

mi = isFormat ? "00毫秒" : "0毫秒";

}

long temp = millis;

long hper = 60 * 60 * 1000;

long mper = 60 * 1000;

long sper = 1000;

if (temp / hper > 0) {

if (isFormat) {

h = temp / hper < 10 ? "0" + temp / hper : temp / hper + "";

} else {

h = temp / hper + "";

}

h += "小時";

}

temp = temp % hper;

if (temp / mper > 0) {

if (isFormat) {

m = temp / mper < 10 ? "0" + temp / mper : temp / mper + "";

} else {

m = temp / mper + "";

}

m += "分";

}

temp = temp % mper;

if (temp / sper > 0) {

if (isFormat) {

s = temp / sper < 10 ? "0" + temp / sper : temp / sper + "";

} else {

s = temp / sper + "";

}

s += "秒";

}

temp = temp % sper;

mi = temp + "";

if (isFormat) {

if (temp < 100 && temp >= 10) {

mi = "0" + temp;

}

if (temp < 10) {

mi = "00" + temp;

}

}

mi += "毫秒";

return h + m + s + mi;

}

格式為小時/分/秒/毫秒(如:24903600 –> 06小時55分03秒)。

/**

*

* @param millis

*? ? ? ? ? ? 要轉(zhuǎn)化的毫秒數(shù)疾嗅。

* @param isWhole

*? ? ? ? ? ? 是否強制全部顯示小時/分/秒/毫秒外厂。

* @param isFormat

*? ? ? ? ? ? 時間數(shù)字是否要格式化,如果true:少位數(shù)前面補全代承;如果false:少位數(shù)前面不補全酣衷。

* @return 返回時間字符串:小時/分/秒/毫秒的格式(如:24903600 --> 06小時55分03秒)。

*/

public static String millisToStringMiddle(long millis, boolean isWhole,

boolean isFormat) {

return millisToStringMiddle(millis, isWhole, isFormat, "小時", "分鐘", "秒");

}

public static String millisToStringMiddle(long millis, boolean isWhole,

boolean isFormat, String hUnit, String mUnit, String sUnit) {

String h = "";

String m = "";

String s = "";

if (isWhole) {

h = isFormat ? "00" + hUnit : "0" + hUnit;

m = isFormat ? "00" + mUnit : "0" + mUnit;

s = isFormat ? "00" + sUnit : "0" + sUnit;

}

long temp = millis;

long hper = 60 * 60 * 1000;

long mper = 60 * 1000;

long sper = 1000;

if (temp / hper > 0) {

if (isFormat) {

h = temp / hper < 10 ? "0" + temp / hper : temp / hper + "";

} else {

h = temp / hper + "";

}

h += hUnit;

}

temp = temp % hper;

if (temp / mper > 0) {

if (isFormat) {

m = temp / mper < 10 ? "0" + temp / mper : temp / mper + "";

} else {

m = temp / mper + "";

}

m += mUnit;

}

temp = temp % mper;

if (temp / sper > 0) {

if (isFormat) {

s = temp / sper < 10 ? "0" + temp / sper : temp / sper + "";

} else {

s = temp / sper + "";

}

s += sUnit;

}

return h + m + s;

}

4次泽、把一個毫秒數(shù)轉(zhuǎn)化成時間字符串穿仪。格式為小時/分/秒/毫秒(如:24903600 –> 06小時55分鐘)

/**

*

* @param millis

*? ? ? ? ? ? 要轉(zhuǎn)化的毫秒數(shù)。

* @param isWhole

*? ? ? ? ? ? 是否強制全部顯示小時/分意荤。

* @param isFormat

*? ? ? ? ? ? 時間數(shù)字是否要格式化啊片,如果true:少位數(shù)前面補全;如果false:少位數(shù)前面不補全玖像。

* @return 返回時間字符串:小時/分/秒/毫秒的格式(如:24903600 --> 06小時55分鐘)紫谷。

*/

public static String millisToStringShort(long millis, boolean isWhole,

boolean isFormat) {

String h = "";

String m = "";

if (isWhole) {

h = isFormat ? "00小時" : "0小時";

m = isFormat ? "00分鐘" : "0分鐘";

}

long temp = millis;

long hper = 60 * 60 * 1000;

long mper = 60 * 1000;

long sper = 1000;

if (temp / hper > 0) {

if (isFormat) {

h = temp / hper < 10 ? "0" + temp / hper : temp / hper + "";

} else {

h = temp / hper + "";

}

h += "小時";

}

temp = temp % hper;

if (temp / mper > 0) {

if (isFormat) {

m = temp / mper < 10 ? "0" + temp / mper : temp / mper + "";

} else {

m = temp / mper + "";

}

m += "分鐘";

}

return h + m;

}

5、把日期毫秒轉(zhuǎn)化為字符串

/**

* @param millis

*? ? ? ? ? ? 要轉(zhuǎn)化的日期毫秒數(shù)捐寥。

* @param pattern

*? ? ? ? ? ? 要轉(zhuǎn)化為的字符串格式(如:yyyy-MM-dd HH:mm:ss)笤昨。

* @return 返回日期字符串。

*/

public static String millisToStringDate(long millis, String pattern) {

SimpleDateFormat format = new SimpleDateFormat(pattern,

Locale.getDefault());

return format.format(new Date(millis));

}

6握恳、把日期毫秒轉(zhuǎn)化為字符串(文件名)

/**

* @param millis

*? ? ? ? ? ? 要轉(zhuǎn)化的日期毫秒數(shù)瞒窒。

* @param pattern

*? ? ? ? ? ? 要轉(zhuǎn)化為的字符串格式(如:yyyy-MM-dd HH:mm:ss)。

* @return 返回日期字符串(yyyy_MM_dd_HH_mm_ss)乡洼。

*/

public static String millisToStringFilename(long millis, String pattern) {

String dateStr = millisToStringDate(millis, pattern);

return dateStr.replaceAll("[- :]", "_");

}

7崇裁、轉(zhuǎn)換當前時間為易用時間格式

1小時內(nèi)用,多少分鐘前束昵; 超過1小時拔稳,顯示時間而無日期; 如果是昨天锹雏,則顯示昨天 超過昨天再顯示日期巴比; 超過1年再顯示年。

public static long oneHourMillis = 60 * 60 * 1000; // 一小時的毫秒數(shù)

public static long oneDayMillis = 24 * oneHourMillis; // 一天的毫秒數(shù)

public static long oneYearMillis = 365 * oneDayMillis; // 一年的毫秒數(shù)

public static String millisToLifeString(long millis) {

long now = System.currentTimeMillis();

long todayStart = string2Millis(millisToStringDate(now, "yyyy-MM-dd"),

"yyyy-MM-dd");

// 一小時內(nèi)

if (now - millis <= oneHourMillis && now - millis > 0l) {

String m = millisToStringShort(now - millis, false, false);

return "".equals(m) ? "1分鐘內(nèi)" : m + "前";

}

// 大于今天開始開始值,小于今天開始值加一天(即今天結(jié)束值)

if (millis >= todayStart && millis <= oneDayMillis + todayStart) {

return "今天 " + millisToStringDate(millis, "HH:mm");

}

// 大于(今天開始值減一天轻绞,即昨天開始值)

if (millis > todayStart - oneDayMillis) {

return "昨天 " + millisToStringDate(millis, "HH:mm");

}

long thisYearStart = string2Millis(millisToStringDate(now, "yyyy"),

"yyyy");

// 大于今天小于今年

if (millis > thisYearStart) {

return millisToStringDate(millis, "MM月dd日 HH:mm");

}

return millisToStringDate(millis, "yyyy年MM月dd日 HH:mm");

}

8腰耙、字符串解析成毫秒數(shù)

public static long string2Millis(String str, String pattern) {

SimpleDateFormat format = new SimpleDateFormat(pattern,

Locale.getDefault());

long millis = 0;

try {

millis = format.parse(str).getTime();

} catch (ParseException e) {

Log.e("TAG", e.getMessage());

}

return millis;

}

9、手機號碼正則

public static final String REG_PHONE_CHINA = "^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";

10铲球、郵箱正則

public static final String REG_EMAIL = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末挺庞,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子稼病,更是在濱河造成了極大的恐慌选侨,老刑警劉巖,帶你破解...
    沈念sama閱讀 223,126評論 6 520
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件然走,死亡現(xiàn)場離奇詭異援制,居然都是意外死亡,警方通過查閱死者的電腦和手機芍瑞,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,421評論 3 400
  • 文/潘曉璐 我一進店門晨仑,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人拆檬,你說我怎么就攤上這事洪己。” “怎么了竟贯?”我有些...
    開封第一講書人閱讀 169,941評論 0 366
  • 文/不壞的土叔 我叫張陵答捕,是天一觀的道長。 經(jīng)常有香客問我屑那,道長拱镐,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 60,294評論 1 300
  • 正文 為了忘掉前任持际,我火速辦了婚禮沃琅,結(jié)果婚禮上欣孤,老公的妹妹穿的比我還像新娘冻押。我一直安慰自己客冈,他們只是感情好衷笋,可當我...
    茶點故事閱讀 69,295評論 6 398
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著啤覆,像睡著了一般帐要。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上殿衰,一...
    開封第一講書人閱讀 52,874評論 1 314
  • 那天,我揣著相機與錄音盛泡,去河邊找鬼闷祥。 笑死,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的凯砍。 我是一名探鬼主播箱硕,決...
    沈念sama閱讀 41,285評論 3 424
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼悟衩!你這毒婦竟也來了剧罩?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 40,249評論 0 277
  • 序言:老撾萬榮一對情侶失蹤座泳,失蹤者是張志新(化名)和其女友劉穎惠昔,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體挑势,經(jīng)...
    沈念sama閱讀 46,760評論 1 321
  • 正文 獨居荒郊野嶺守林人離奇死亡镇防,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,840評論 3 343
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了潮饱。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片来氧。...
    茶點故事閱讀 40,973評論 1 354
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖香拉,靈堂內(nèi)的尸體忽然破棺而出啦扬,到底是詐尸還是另有隱情,我是刑警寧澤凫碌,帶...
    沈念sama閱讀 36,631評論 5 351
  • 正文 年R本政府宣布考传,位于F島的核電站,受9級特大地震影響证鸥,放射性物質(zhì)發(fā)生泄漏僚楞。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 42,315評論 3 336
  • 文/蒙蒙 一枉层、第九天 我趴在偏房一處隱蔽的房頂上張望泉褐。 院中可真熱鬧,春花似錦鸟蜡、人聲如沸膜赃。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,797評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽跳座。三九已至,卻和暖如春泣矛,著一層夾襖步出監(jiān)牢的瞬間疲眷,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,926評論 1 275
  • 我被黑心中介騙來泰國打工您朽, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留狂丝,地道東北人。 一個月前我還...
    沈念sama閱讀 49,431評論 3 379
  • 正文 我出身青樓,卻偏偏與公主長得像几颜,于是被迫代替她去往敵國和親倍试。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 45,982評論 2 361

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

  • ¥開啟¥ 【iAPP實現(xiàn)進入界面執(zhí)行逐一顯】 〖2017-08-25 15:22:14〗 《//首先開一個線程蛋哭,因...
    小菜c閱讀 6,453評論 0 17
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理县习,服務(wù)發(fā)現(xiàn),斷路器谆趾,智...
    卡卡羅2017閱讀 134,722評論 18 139
  • 主要積累一些開發(fā)中比較 常用的工具類躁愿,部分借鑒于網(wǎng)絡(luò),主要來源于平時開發(fā)因需求而生的小工具類 13棺妓、ArithUt...
    大鴨梨leepear閱讀 672評論 0 1
  • #Android 基礎(chǔ)知識點總結(jié) ---------- ##1.adb - android debug bridg...
    Mythqian閱讀 3,302評論 2 11
  • 先Activity的抽象類 BaseActivity [java]view plaincopy /** *Acti...
    Zaker2Magic閱讀 982評論 0 0