I'm developing a project that uses the Internet. My problem is that check it out on the internet with the Internet Is connected or not? Code but error occurs
Click on Public Zero (see V) {Connectivity Manager = CM (Connectivity Manager) getSystemService (reference. CONNECTIVITY_SERVICE); Network Info Info = CmsActactNetworkInfo (); Boolean A = CmActactNetworkEnfo () IsConnectedOrConnecting (); If (a == true) {toast ("connect"); } And {toast ("not connected"); }}
Please try below the function. If the internet connection is available in the device then it will return the truth or else it will return false.
Public Static Boolean CheckInnet (Reference Reference) {Connectivity Manager Connection = (Connectivity Manager) context.getSystemService (context.CONNECTIVITY_SERVICE); Android.net.NetworkInfo wifi = connec.getNetworkInfo (Connectivity Manager. TYPE_WIFI); Android.net NetworkInfo Mobile = Connection NetNetworkInfo (Connectivity Manager. TEP_MOBIELE); If (wifi.isconnected ()) {return true; } Else if (mobile.isConnected ()) {back true; } return false; } Add permission to the Android Manifest file.
Android: Permission to use - Android: name = "android.permission.ACCESS_NETWORK_STATE" />
Comments
Post a Comment