This is the code for checking network connection and rise condition to true or false

//Needs RequestNetwork to work!
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
connected = (netInfo != null && netInfo.isConnectedOrConnecting());
if (connected) {
SketchwareUtil.showMessage(getApplicationContext(), “Connected!”);
else {
SketchwareUtil.showMessage(getApplicationContext(), “Not connected!”);

There are two profit in this code. 1st you can check network connection and 2nd is performed any action with true and false.

To perform any action just replace your code with set text block.