Check Internet connection in sketchware made app

Check Internet connection in sketchware made app

Today we will see How to check internet connection availability in your app made using sketchware.

Hi there today in this post we will configure our app so that it will check internet connection availability every time we open it. We also see how we can stop loading webview if there is no internet connection available.

I will be discussing 2 different method in two different post.

The first method is here to read. The second one is available in this post.

Let’s just start this tutorial

Step 1: Set the on create event

Go to on create event and add a webview load url block. Leave this empty in order to add internet permissions and then add a add source directly block and paste the below code

isNetworkConnectionAvailable();

Step 2: Create a more block

Create aa more block called connection

And set this as below image

Code for The add source directly block 1


}
public void checkNetworkConnection(){
    AlertDialog.Builder builder =new AlertDialog.Builder(this);
    builder.setTitle("No internet Available");
    builder.setMessage("Turn on internet connection to continue");
    builder.setNegativeButton("Try Again", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
isNetworkConnectionAvailable();
        }
    });
    AlertDialog alertDialog = builder.create();

alertDialog.setCanceledOnTouchOutside(false);

alertDialog.setIcon(R.drawable.net);
    alertDialog.show();
}

public boolean isNetworkConnectionAvailable(){
    ConnectivityManager cm =
            (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null &&
            activeNetwork.isConnected();
    if(isConnected) {

        

You can change title and the message of your internet connection checker block by changing the above code

The second add source directly block is

Log.d("Network", "Connected");
        return true;

 
    }
    else{
        checkNetworkConnection();
        Log.d("Network","Not Connected");
        return false;
    }
}
{

The internet connection dialog will look like this

Step 3 : Add an image

We need to add an image in order to show a custom image in your alert dialog. You need to name this image as ‘net’ otherwise your app will show error.

Now just run your project and see the magic. I have also discussed a different method to stop loading webview if there is no internet connection available.

Thanks for reading.

This Post Has 6 Comments

  1. Jham

    How to add an image? You dont mention it?

    1. Kaushik

      Hi, Jham just go to your sketchware app and open your project. then click on the 3 dots in thee right upper corner, and then click on image option and then click on add image option. and you are done, name the image as I said. otherwise it will through error. sorry for the late reply

  2. Benjamin

    Doesn’t work

    1. Kaushik

      please tell me what went wrong, so that I can help you out.

  3. Mohammad Ullah

    Thanks a lot, i am successfully added a custom no internet screen on my web app

    To comment readers: in mainActivity.xml line 87 you will find (net) image required,, so you can add the image from three dot menu.. Thanks all

  4. Charlesnax

    Hello, what’s new?

Leave a Reply