Required Code to Control Android Internet

in #tecnology7 years ago

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.

<uses-permission android: name = "android.permission.ACCESS_NETWORK_ST ATE" />

.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

}

Sort:  

Congratulations @tunar! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!