Last active
June 5, 2018 23:53
-
-
Save Fast0n/a5f11a490a9f38967d3ce510572dc50b to your computer and use it in GitHub Desktop.
Check internet connection Android Studio
This file contains 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
#### AndroidManifest.xml #### | |
<uses-permission android:name="android.permission.INTERNET"/> | |
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | |
#### MainActivity.java #### | |
public boolean isOnline() { | |
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); | |
return (cm != null ? cm.getActiveNetworkInfo() : null) != null && cm.getActiveNetworkInfo().isConnectedOrConnecting(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment