What is the method for android to obtain and monitor the status of mobile phone network?
Most people do not understand the knowledge points of this article "what is the method of android access and monitoring mobile phone network status?", so the editor summarizes the following content for you, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what is the method of android access and monitoring mobile phone network status".
1. Obtain whether the current mobile networking method is WiFi or mobile 4G data private boolean getNetworkType () {ConnectivityManager mConnectivity = (ConnectivityManager) getSystemService (Context.CONNECTIVITY_SERVICE); / / check the network link NetworkInfo info = mConnectivity.getActiveNetworkInfo (); int netType = mConnectivity.getActiveNetworkInfo (). GetType () If (netType = = ConnectivityManager.TYPE_WIFI) {/ / WIFI ChangYouLog.i (TAG, "currently WIFI connection isConnected =" + info.isConnected ()); return info.isConnected ();} else if (netType = = ConnectivityManager.TYPE_MOBILE) {/ / MOBILE ChangYouLog.i (TAG, "currently mobile network connection isConnected =" + info.isConnected ()); return info.isConnected () } else {ChangYouLog.i (TAG, "currently no network connection isConnected =" + info.isConnected ()); return false 2. Monitor mobile network changes private class MyBroadcastReceiver extends BroadcastReceiver {@ Override public void onReceive (Context context, Intent intent) {if (intent.getAction (). Equals (ConnectivityManager.CONNECTIVITY_ACTION)) {/ / monitor network connection / / get the NetworkInfo object NetworkInfo info = intent.getParcelableExtra (ConnectivityManager.EXTRA_NETWORK_INFO) If (info! = null) {/ / if the current network connection is successful and the network connection is available if (NetworkInfo.State.CONNECTED = = info.getState () & & info.isAvailable ()) {if (info.getType () = = ConnectivityManager.TYPE_WIFI) {ChangYouLog.i (TAG) "connect to WiFi") } else if (info.getType () = = ConnectivityManager.TYPE_MOBILE) {ChangYouLog.i (TAG, "connecting Mobile Network data"); CYouLbyMicroClient.getInstance () .gameEvent ("Network_4G_reminder") }} else {ChangYouLog.i (TAG, "Network disconnected");}}
Note: network status permissions need to be added
The above is the content of this article on "what is the method of android obtaining and monitoring mobile phone network status". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more related knowledge, please pay attention to the industry information channel.