P
P
Prowebic2016-05-02 17:03:06
Android
Prowebic, 2016-05-02 17:03:06

How to determine through the application whether there is an Internet or not?

How to determine whether the user is connected to the Internet through the application or not? It is necessary to determine this moment right at the very opening of the application.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sergiu3dmd, 2016-05-03
@Prowebic

public boolean isOnline() {
        ConnectivityManager cm =
                (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = cm.getActiveNetworkInfo();
        return netInfo != null && netInfo.isConnectedOrConnecting();
    }

G
GavriKos, 2016-05-02
@GavriKos

Ping google. Pinging - yes, not pinging - no

A
Alexey, 2016-05-02
@alsopub

Windows, for example, makes a request to www.msftncsi.com/ncsi.txt and if 200 Ok - the network is available.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question