Android keyboard display control, network check, network monitoring, and android Network Monitoring
I. The operation of hiding the input and display keyboards is often used. The control code is pasted here:
// Disable the comfortable keyboard method public static void collapseSoftInputMethod (Context context, View v) {if (v! = Null) {InputMethodManager imm = (InputMethodManager) context. getSystemService (Context. INPUT_METHOD_SERVICE); imm. hideSoftInputFromWindow (v. getWindowToken (), 0) ;}// display the input method public static void showSoftInputMethod (Context context, View v) {if (v! = Null) {InputMethodManager imm = (InputMethodManager) context. getSystemService (Context. INPUT_METHOD_SERVICE); imm. showSoftInput (v, 0 );}}
2. Check whether the Network is available
/*** @ Name: checkNetwork * @ Description: Check the current network * @ param: none * @ return: true -- network has false --- no Network */public boolean checkNetwork () {ConnectivityManager conn = (ConnectivityManager) getSystemService (Context. CONNECTIVITY_SERVICE); NetworkInfo net = conn. getActiveNetworkInfo (); if (net! = Null & net. isConnected () {return true;} return false ;}
Check whether wifi is available
public boolean isWifiConnected(Context context) { if (context != null) { ConnectivityManager mConnectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mWiFiNetworkInfo = mConnectivityManager .getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (mWiFiNetworkInfo != null) { return mWiFiNetworkInfo.isAvailable(); } } return false; }
3. Check whether the mobile network is available
public boolean isMobileConnected(Context context) { if (context != null) { ConnectivityManager mConnectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mMobileNetworkInfo = mConnectivityManager .getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (mMobileNetworkInfo != null) { return mMobileNetworkInfo.isAvailable(); } } return false; }
Iv. Check the current network type
public static int getConnectedType(Context context) { if (context != null) { ConnectivityManager mConnectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo(); if (mNetworkInfo != null && mNetworkInfo.isAvailable()) { return mNetworkInfo.getType(); } } return -1; }
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.