Example usage for android.net ConnectivityManager TYPE_ETHERNET

List of usage examples for android.net ConnectivityManager TYPE_ETHERNET

Introduction

In this page you can find the example usage for android.net ConnectivityManager TYPE_ETHERNET.

Prototype

int TYPE_ETHERNET

To view the source code for android.net ConnectivityManager TYPE_ETHERNET.

Click Source Link

Document

An Ethernet data connection.

Usage

From source file:de.geeksfactory.opacclient.reminder.SyncAccountService.java

@Override
protected void doWakefulWork(Intent intent) {
    if (BuildConfig.DEBUG)
        Log.i(NAME, "SyncAccountService started");

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);

    if (!sp.getBoolean(SyncAccountAlarmListener.PREF_SYNC_SERVICE, false)) {
        if (BuildConfig.DEBUG)
            Log.i(NAME, "notifications are disabled");
        return;/* w ww .j  ava  2  s.co m*/
    }

    ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo != null) {
        if (!sp.getBoolean("notification_service_wifionly", false)
                || networkInfo.getType() == ConnectivityManager.TYPE_WIFI
                || networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET) {
            syncAccounts();
        } else {
            failed = true;
        }
    } else {
        failed = true;
    }

    if (BuildConfig.DEBUG) {
        Log.i(NAME, "SyncAccountService finished " + (failed ? " with errors" : " " + "successfully"));
    }

    long previousPeriod = sp.getLong(SyncAccountAlarmListener.PREF_SYNC_INTERVAL, 0);
    long newPeriod = failed ? AlarmManager.INTERVAL_HOUR : AlarmManager.INTERVAL_HALF_DAY;
    if (previousPeriod != newPeriod) {
        sp.edit().putLong(SyncAccountAlarmListener.PREF_SYNC_INTERVAL, newPeriod).apply();
        WakefulIntentService.cancelAlarms(this);
        WakefulIntentService.scheduleAlarms(SyncAccountAlarmListener.withOnePeriodBeforeStart(), this);
    }
}

From source file:com.seadee.library.receiver.NetworkStateReceiver.java

public boolean isEthernetConnected() {
    if (connectmanager == null)
        connectmanager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    return connectmanager.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET).isConnected();
}

From source file:com.seadee.degree.service.NetworkStateReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    if (connectmanager == null)
        connectmanager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    wifistate = connectmanager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected();
    ethernetstate = connectmanager.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET).isConnected();

    if (wifistate) {
        SettingVarible.networkstate = SettingVarible.NETWORKSTATE.WIFI;
        isConnect = false;/*from  w w  w.  j  a  v  a 2s. c  o  m*/
    } else if (ethernetstate) {
        SettingVarible.networkstate = SettingVarible.NETWORKSTATE.ETHERNET;
        isConnect = false;
    }

    /*if(wifistate||ethernetstate)
    {
       if(FirstConnect)
       {
    HomeActivity.getInstance().handler.sendEmptyMessage(HomeActivity.FIRSTNETWORK);
    FirstConnect=false;
       }   
    }
    else
    {
       SettingVarible.networkstate=SettingVarible.NETWORKSTATE.NONETWORK;
       if(SessionActivity.getInstance()!=null)
       {
    SessionActivity.getInstance().uiHandler.sendEmptyMessage(SessionActivity.UIHandler.NETWORK_DISCONNECT);
       }
    }
    HomeActivity.getInstance().handler.sendEmptyMessage(HomeActivity.SWITCHNETWORKICON);*/
    SettingVarible.ipAddress = getLocalIpAddress(context);
}

From source file:org.openhab.habdroid.ui.OpenHABStartupActivity.java

private void initPage() {

    if (!tryManualUrl()) {
        ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(
                Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
        if (activeNetworkInfo != null) {
            Log.i(TAG, "Network is connected");
            if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI
                    || activeNetworkInfo.getType() == ConnectivityManager.TYPE_ETHERNET) {
                Log.i(TAG, "Network is WiFi or Ethernet");
                AsyncServiceResolver serviceResolver = new AsyncServiceResolver(this, openHABServiceType);
                if (!this.isFinishing())
                    progressDialog = ProgressDialog.show(OpenHABStartupActivity.this, "",
                            "Discovering openHAB. Please wait...", true);
                serviceResolver.start();
            } else if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
                Log.i(TAG, "Network is Mobile (" + activeNetworkInfo.getSubtypeName() + ")");
                onAlternativeUrl();/*w w w.  j  a  va  2s .c o m*/
            } else {
                Log.i(TAG, "Network type (" + activeNetworkInfo.getTypeName() + ") is unsupported");
            }
        } else {
            Log.i(TAG, "Network is not available");
            Toast.makeText(getApplicationContext(), "@string/error_network_not_available", Toast.LENGTH_LONG)
                    .show();
        }
    }

}

From source file:de.geeksfactory.opacclient.reminder.ReminderCheckService.java

@Override
public int onStartCommand(Intent intent, int flags, int startid) {
    if (ACTION_SNOOZE.equals(intent.getAction())) {
        Intent i = new Intent(ReminderCheckService.this, ReminderAlarmReceiver.class);
        PendingIntent sender = PendingIntent.getBroadcast(ReminderCheckService.this,
                OpacClient.BROADCAST_REMINDER, i, PendingIntent.FLAG_UPDATE_CURRENT);
        AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

        Log.i("ReminderCheckService", "Opac App Service: Quick repeat");
        // Run again in 1 day
        am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (1000 * 3600 * 24), sender);

        NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        mNotificationManager.cancel(OpacClient.NOTIF_ID);
    } else {//from  www. j a v a 2s .com
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(ReminderCheckService.this);
        notification_on = sp.getBoolean("notification_service", false);
        long waittime = (1000 * 3600 * 5);
        boolean executed = false;

        ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
        if (networkInfo != null) {
            if (!sp.getBoolean("notification_service_wifionly", false)
                    || networkInfo.getType() == ConnectivityManager.TYPE_WIFI
                    || networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET) {
                executed = true;
                new CheckTask().execute();
            } else {
                waittime = (1000 * 1800);
            }
        } else {
            waittime = (1000 * 1800);
        }

        if (!notification_on) {
            waittime = (1000 * 3600 * 12);
        }

        Intent i = new Intent(ReminderCheckService.this, ReminderAlarmReceiver.class);
        PendingIntent sender = PendingIntent.getBroadcast(ReminderCheckService.this,
                OpacClient.BROADCAST_REMINDER, i, PendingIntent.FLAG_UPDATE_CURRENT);
        AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + waittime, sender);

        if (!executed) {
            stopSelf();
        }
    }

    return START_NOT_STICKY;
}

From source file:net.mm2d.dmsexplorer.ServerListActivity.java

private boolean hasAvailableNetwork() {
    final NetworkInfo ni = mConnectivityManager.getActiveNetworkInfo();
    return ni != null && ni.isConnected() && (ni.getType() == ConnectivityManager.TYPE_WIFI
            || ni.getType() == ConnectivityManager.TYPE_ETHERNET);
}

From source file:com.onesignal.OSUtils.java

Integer getNetType() {
    ConnectivityManager cm = (ConnectivityManager) OneSignal.appContext
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();

    if (netInfo != null) {
        int networkType = netInfo.getType();
        if (networkType == ConnectivityManager.TYPE_WIFI || networkType == ConnectivityManager.TYPE_ETHERNET)
            return 0;
        return 1;
    }//w w w. ja  va  2 s.c  o m

    return null;
}

From source file:com.just.agentweb.AgentWebUtils.java

public static int checkNetworkType(Context context) {

    int netType = 0;
    //?/* www .  j a  v a  2  s  .  co m*/
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    //?NetworkInfo
    @SuppressLint("MissingPermission")
    NetworkInfo networkInfo = manager.getActiveNetworkInfo();
    if (networkInfo == null) {
        return netType;
    }
    switch (networkInfo.getType()) {
    case ConnectivityManager.TYPE_WIFI:
    case ConnectivityManager.TYPE_WIMAX:
    case ConnectivityManager.TYPE_ETHERNET:
        return 1;

    case ConnectivityManager.TYPE_MOBILE:
        switch (networkInfo.getSubtype()) {
        case TelephonyManager.NETWORK_TYPE_LTE: // 4G
        case TelephonyManager.NETWORK_TYPE_HSPAP:
        case TelephonyManager.NETWORK_TYPE_EHRPD:
            return 2;
        case TelephonyManager.NETWORK_TYPE_UMTS: // 3G
        case TelephonyManager.NETWORK_TYPE_CDMA:
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
        case TelephonyManager.NETWORK_TYPE_EVDO_B:
            return 3;

        case TelephonyManager.NETWORK_TYPE_GPRS: // 2G
        case TelephonyManager.NETWORK_TYPE_EDGE:
            return 4;

        default:
            return netType;
        }

    default:

        return netType;
    }

}

From source file:dev.ukanth.ufirewall.InterfaceTracker.java

private static InterfaceDetails getInterfaceDetails(Context context) {
    InterfaceDetails ret = new InterfaceDetails();

    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();

    if (info == null || info.isConnected() == false) {
        return ret;
    }/*from  w  ww.jav a  2s. c om*/

    switch (info.getType()) {
    case ConnectivityManager.TYPE_MOBILE:
    case ConnectivityManager.TYPE_MOBILE_DUN:
    case ConnectivityManager.TYPE_MOBILE_HIPRI:
    case ConnectivityManager.TYPE_MOBILE_MMS:
    case ConnectivityManager.TYPE_MOBILE_SUPL:
    case ConnectivityManager.TYPE_WIMAX:
        ret.isRoaming = info.isRoaming();
        ret.netType = ConnectivityManager.TYPE_MOBILE;
        ret.netEnabled = true;
        break;
    case ConnectivityManager.TYPE_WIFI:
    case ConnectivityManager.TYPE_BLUETOOTH:
    case ConnectivityManager.TYPE_ETHERNET:
        ret.netType = ConnectivityManager.TYPE_WIFI;
        ret.netEnabled = true;
        break;
    }
    getTetherStatus(context, ret);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
        OldInterfaceScanner.populateLanMasks(context, ITFS_WIFI, ret);
    } else {
        NewInterfaceScanner.populateLanMasks(context, ITFS_WIFI, ret);
    }

    return ret;
}

From source file:org.gateshipone.malp.application.artworkdatabase.BulkDownloadService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    if (intent != null && intent.getAction() != null && intent.getAction().equals(ACTION_START_BULKDOWNLOAD)) {
        Log.v(TAG, "Starting bulk download in service with thread id: " + Thread.currentThread().getId());

        // reset counter
        mRemainingArtists = 0;/*from w  w  w.j av  a2  s .c  om*/
        mRemainingAlbums = 0;
        mSumImageDownloads = 0;

        String artistProvider = getString(R.string.pref_artwork_provider_artist_default);
        String albumProvider = getString(R.string.pref_artwork_provider_album_default);
        mWifiOnly = true;

        // read setting from extras
        Bundle extras = intent.getExtras();
        if (extras != null) {
            artistProvider = extras.getString(BUNDLE_KEY_ARTIST_PROVIDER,
                    getString(R.string.pref_artwork_provider_artist_default));
            albumProvider = extras.getString(BUNDLE_KEY_ALBUM_PROVIDER,
                    getString(R.string.pref_artwork_provider_album_default));
            mWifiOnly = intent.getBooleanExtra(BUNDLE_KEY_WIFI_ONLY, true);
        }

        ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo netInfo = cm.getActiveNetworkInfo();
        if (null == netInfo) {
            return START_NOT_STICKY;
        }
        boolean isWifi = netInfo.getType() == ConnectivityManager.TYPE_WIFI
                || netInfo.getType() == ConnectivityManager.TYPE_ETHERNET;

        if (mWifiOnly && !isWifi) {
            return START_NOT_STICKY;
        }

        PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
        mWakelock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MALP_BulkDownloader");

        ArtworkManager artworkManager = ArtworkManager.getInstance(getApplicationContext());
        artworkManager.initialize(artistProvider, albumProvider, mWifiOnly);

        // FIXME do some timeout checking. e.g. 5 minutes no new image then cancel the process
        mWakelock.acquire();
        ConnectionManager.reconnectLastServer(this);
    }
    return START_NOT_STICKY;

}