Created
April 4, 2018 07:25
-
-
Save rosuH/ed51607d4d9126b80ef7ac690ba6c8ff to your computer and use it in GitHub Desktop.
Judge whether the network is available.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private boolean isNetworkAvailableAndConnected() { | |
| ConnectivityManager cm = (ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE); | |
| boolean isNetworkAvailable = cm.getActiveNetworkInfo() != null; | |
| boolean isNetworkConnected = isNetworkAvailable && cm.getActiveNetworkInfo().isConnected(); | |
| return isNetworkConnected; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />inAndroidManifest.xml