Question Detail

when internet not connected to my mobile or disable application should display an Alert about NO INTERNET CONNECTION FOUND PLEASE CHECK YOUR NETWORK.
How can I know that internet not working or Not connected Programmatically?

No Internet Connected sweetalertdialog QnA

Thread Reply

Correct Answer

Hemant Sharma

- 2 years ago

import android.content.Context;
import android.content.Intent;
import android.provider.Settings;

import cn.pedant.SweetAlert.SweetAlertDialog;

 * Created by Hemant on 8/8/2017.

public class InternetConnectionCheck {
    static Context context;
    void InternetConnectionCheck(){
    public static boolean isConnectingToInternet(Context applicationContext) {
        ConnectivityManager cm = (ConnectivityManager)applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo ni = cm.getActiveNetworkInfo();
        if (ni == null) {
            new SweetAlertDialog(applicationContext, SweetAlertDialog.ERROR_TYPE)
                    .setTitleText("No Internet Connection!")
                    .setContentText("Please Check Internet Connection.")
                    .setCancelText("It's Okay")
                    .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
                        public void onClick(SweetAlertDialog sDialog) {
                            context.startActivity(new Intent(Settings.ACTION_NETWORK_OPERATOR_SETTINGS));

            return false;
        } else
            return true;