Check Internet Connection On Sketchware

Today i will share How to Check Internet Connection On Sketchware .


You must need To Get Internet permission
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 


    Method/Code 1 :

    android.net.ConnectivityManager cm = (android.net.ConnectivityManager) this.getSystemService(android.content.Context.CONNECTIVITY_SERVICE); android.net.NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (activeNetwork != null) { if (activeNetwork.getType() == android.net.ConnectivityManager.TYPE_WIFI) { text.setText("Wifi is active"); } else if (activeNetwork.getType() == android.net.ConnectivityManager.TYPE_MOBILE) {
    text.setText("mobile is active");
    }
    } else {
     text.setText("No connection");
     }


    Method / Code 2: 

    android.net.ConnectivityManager connMgr = (android.net.ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
     android.net.NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
     // set or fetch data
     }
     else { // display error }