Required Code to Control Android Internet

By @tunar11/25/2017tecnology

Hi Android developers, if you need internet for the program you are developing, you need to check the internet in this case. But how are you going to do it? Here we will share the necessary codes with you.

manifest.xml

We add the following code to my manifest file and request the required permissions.

.Necessary Method in Java File

The following code is set as the method and we are adding .java files.

public boolean internetKontrolEt () {
connectivity = (ConnectivityManager) getSystemService (Context.CONNECTIVITY_SERVICE);
if (connectivity.getactivenetworkınfo ()! = null) {
if (connectivity.getActiveNetworkInfo (). isConnected ())
return true;
}
return false;
}
/ * Webinyo.COM Android Programming * /

Using the following code, if you have internet, what you want to do or not, we add the necessary code to the required fields.

if (internetkontrolet ()) {

// Codes we want to run if there are connections

} Else {

// Codes we want to run if there is no connection

}

1

comments