Search in sources :

Example 56 with NetworkInfo

use of android.net.NetworkInfo in project Android by hmkcode.

the class MainActivity method isConnected.

public boolean isConnected() {
    ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Activity.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected())
        return true;
    else
        return false;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 57 with NetworkInfo

use of android.net.NetworkInfo in project packer-ng-plugin by mcxiaoke.

the class MainActivity method addNetworkInfoSection.

private void addNetworkInfoSection() {
    StringBuilder builder = new StringBuilder();
    builder.append("[Network]\n");
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    if (info != null) {
        builder.append(info);
    }
    builder.append("\n\n");
    addSection(builder.toString());
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 58 with NetworkInfo

use of android.net.NetworkInfo in project LollipopShowcase by mikepenz.

the class Network method isAvailiable.

public static boolean isAvailiable(Context ctx) {
    ConnectivityManager conMgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo i = conMgr.getActiveNetworkInfo();
    if (i == null)
        return false;
    if (!i.isConnected())
        return false;
    if (!i.isAvailable())
        return false;
    return true;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 59 with NetworkInfo

use of android.net.NetworkInfo in project qksms by moezbhatti.

the class Transaction method sendMMS.

private void sendMMS(final byte[] bytesToSend) {
    revokeWifi(true);
    // enable mms connection to mobile data
    mConnMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    int result = beginMmsConnectivity();
    if (LOCAL_LOGV)
        Log.v(TAG, "result of connectivity: " + result + " ");
    if (result != 0) {
        // if mms feature is not already running (most likely isn't...) then register a receiver and wait for it to be active
        IntentFilter filter = new IntentFilter();
        filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        final BroadcastReceiver receiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context1, Intent intent) {
                String action = intent.getAction();
                if (!action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
                    return;
                }
                @SuppressWarnings("deprecation") NetworkInfo mNetworkInfo = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
                if ((mNetworkInfo == null) || (mNetworkInfo.getType() != ConnectivityManager.TYPE_MOBILE)) {
                    return;
                }
                if (!mNetworkInfo.isConnected()) {
                    return;
                } else {
                    // ready to send the message now
                    if (LOCAL_LOGV)
                        Log.v(TAG, "sending through broadcast receiver");
                    alreadySending = true;
                    sendData(bytesToSend);
                    context.unregisterReceiver(this);
                }
            }
        };
        context.registerReceiver(receiver, filter);
        try {
            Looper.prepare();
        } catch (Exception e) {
        // Already on UI thread probably
        }
        // try sending after 3 seconds anyways if for some reason the receiver doesn't work
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                if (!alreadySending) {
                    try {
                        if (LOCAL_LOGV)
                            Log.v(TAG, "sending through handler");
                        context.unregisterReceiver(receiver);
                    } catch (Exception e) {
                    }
                    sendData(bytesToSend);
                }
            }
        }, 7000);
    } else {
        // mms connection already active, so send the message
        if (LOCAL_LOGV)
            Log.v(TAG, "sending right away, already ready");
        sendData(bytesToSend);
    }
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) NetworkInfo(android.net.NetworkInfo) Handler(android.os.Handler) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) MmsException(com.google.android.mms.MmsException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 60 with NetworkInfo

use of android.net.NetworkInfo in project nmid-headline by miao1007.

the class NetworkUtils method isNetworkAvailable.

public boolean isNetworkAvailable(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Aggregations

NetworkInfo (android.net.NetworkInfo)511 ConnectivityManager (android.net.ConnectivityManager)274 Intent (android.content.Intent)47 LinkProperties (android.net.LinkProperties)38 NetworkState (android.net.NetworkState)26 Test (org.junit.Test)26 PendingIntent (android.app.PendingIntent)23 NetworkCapabilities (android.net.NetworkCapabilities)18 Network (android.net.Network)17 LargeTest (android.test.suitebuilder.annotation.LargeTest)17 RemoteException (android.os.RemoteException)16 Context (android.content.Context)15 NetworkAgentInfo (com.android.server.connectivity.NetworkAgentInfo)15 WifiInfo (android.net.wifi.WifiInfo)13 Bundle (android.os.Bundle)13 TestUtils.mockNetworkInfo (com.squareup.picasso.TestUtils.mockNetworkInfo)12 IOException (java.io.IOException)11 WifiManager (android.net.wifi.WifiManager)9 IntentFilter (android.content.IntentFilter)8 BroadcastReceiver (android.content.BroadcastReceiver)7