Android Tips(二) 发表于 2015-09-20 | 分类于 Android | | 阅读次数 判断应用是否联网1234567891011121314151617/** * 判断是否联网 * * @param context * @return boolean true,已联网;false,断网状态 */public static boolean isNetwork(Context context) { try { ConnectivityManager manger = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = manger.getActiveNetworkInfo(); return (info != null && info.isConnected()); } catch (Exception e) { Log.e(TAG, "判断是否有网络出错"); return false; }} 判断字符是否中文1234567891011121314151617181920/** * @Description: 判断字符是否中文 * @param c * 字符 * @return boolean * @author * @data */public boolean isChinese(char c) { Character.UnicodeBlock ub = Character.UnicodeBlock.of(c); if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) { return true; } return false;} 显示/隐藏软键盘123456789101112131415/* 显示软键盘 */public void ShowSoftKeyborad(Context context) { InputMethodManager inputMethodManager = (InputMethodManager) context .getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.showSoftInput(this, InputMethodManager.RESULT_UNCHANGED_SHOWN);}/* 隐藏软键盘 */public void hideSoftKeyborad(Context context) { InputMethodManager inputMethodManager = (InputMethodManager) context .getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(getWindowToken(), InputMethodManager.RESULT_UNCHANGED_HIDDEN);}