Example usage for android.net NetworkInfo getType

List of usage examples for android.net NetworkInfo getType

Introduction

In this page you can find the example usage for android.net NetworkInfo getType.

Prototype

@Deprecated
public int getType() 

Source Link

Document

Reports the type of network to which the info in this NetworkInfo pertains.

Usage

From source file:com.thejoshwa.ultrasonic.androidapp.util.Util.java

public static int getMaxVideoBitrate(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = manager.getActiveNetworkInfo();
    if (networkInfo == null) {
        return 0;
    }//from   www .j a  v a  2s .c  om

    boolean wifi = networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
    SharedPreferences prefs = getPreferences(context);
    return Integer.parseInt(prefs.getString(wifi ? Constants.PREFERENCES_KEY_MAX_VIDEO_BITRATE_WIFI
            : Constants.PREFERENCES_KEY_MAX_VIDEO_BITRATE_MOBILE, "0"));
}

From source file:com.thejoshwa.ultrasonic.androidapp.util.Util.java

public static int getMaxBitrate(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = manager.getActiveNetworkInfo();
    if (networkInfo == null) {
        return 0;
    }//from  ww  w . j  a va 2s.c  o  m

    boolean wifi = networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
    SharedPreferences prefs = getPreferences(context);
    return Integer.parseInt(prefs.getString(
            wifi ? Constants.PREFERENCES_KEY_MAX_BITRATE_WIFI : Constants.PREFERENCES_KEY_MAX_BITRATE_MOBILE,
            "0"));
}

From source file:net.helff.wificonnector.WifiConnectivityReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Log.i(TAG, "action: " + intent.getAction());

    if (intent.getAction().equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {

        Intent locationIntent = new LocationIntent();
        context.sendBroadcast(locationIntent);
    }/*from  w  w w.  j  av  a  2s.co  m*/

    if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {

        NetworkInfo networkInfo = (NetworkInfo) intent
                .getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);

        Log.d(TAG, "got network_state_changed with detailed info: " + networkInfo == null ? "nothing"
                : networkInfo.getDetailedState().name());

        if (networkInfo != null && networkInfo.isConnected()
                && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
            boolean autoConnect = prefs.getBoolean("autoConnect", false);

            Log.d(TAG, "triggering WifiConnectivityService with autoConnect=" + autoConnect);

            int command = autoConnect ? WifiConnectivityService.COMMAND_AUTO_UNLOCK_CONNECTION
                    : WifiConnectivityService.COMMAND_CHECK_CONNECTION;
            Intent msgIntent = new Intent(context, WifiConnectivityService.class);
            msgIntent.putExtra(WifiConnectivityService.INTENT_COMMAND, command);
            context.startService(msgIntent);
        }

    }
    if (intent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
        Log.d(TAG, "triggering WifiConnectivityService state changed");

        Intent msgIntent = new Intent(context, WifiConnectivityService.class);
        msgIntent.putExtra(WifiConnectivityService.INTENT_COMMAND,
                WifiConnectivityService.COMMAND_REFRESH_STATUS);
        context.startService(msgIntent);
    }
}

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

private Collection<NetworkInterface> getWifiInterface() {
    final NetworkInfo ni = mConnectivityManager.getActiveNetworkInfo();
    if (ni == null || !ni.isConnected() || ni.getType() != ConnectivityManager.TYPE_WIFI) {
        return null;
    }/*from www .  j a v  a2  s  .com*/
    final InetAddress address = getWifiInetAddress();
    if (address == null) {
        return null;
    }
    final Enumeration<NetworkInterface> nis;
    try {
        nis = NetworkInterface.getNetworkInterfaces();
    } catch (final SocketException e) {
        return null;
    }
    while (nis.hasMoreElements()) {
        final NetworkInterface nif = nis.nextElement();
        try {
            if (nif.isLoopback() || nif.isPointToPoint() || nif.isVirtual() || !nif.isUp()) {
                continue;
            }
            final List<InterfaceAddress> ifas = nif.getInterfaceAddresses();
            for (final InterfaceAddress a : ifas) {
                if (a.getAddress().equals(address)) {
                    final Collection<NetworkInterface> c = new ArrayList<>();
                    c.add(nif);
                    return c;
                }
            }
        } catch (final SocketException ignored) {
        }
    }
    return null;
}

From source file:github.daneren2005.dsub.util.Util.java

public static boolean isWifiConnected(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = manager.getActiveNetworkInfo();
    boolean connected = networkInfo != null && networkInfo.isConnected();
    return connected && (networkInfo.getType() == ConnectivityManager.TYPE_WIFI);
}

From source file:cn.edu.szjm.support.http.IgnitedHttp.java

/**
 * Updates the underlying HTTP client's proxy settings with what the user has entered in the APN
 * settings. This will be called automatically if {@link #listenForConnectivityChanges(Context)}
 * has been called. <b>This requires the {@link Manifest.permission#ACCESS_NETWORK_STATE}
 * permission</b>./*  ww w  . j  a va2  s . c o m*/
 * 
 * @param context
 *            the current context
 */
public void updateProxySettings(Context context) {
    if (context == null) {
        return;
    }
    HttpParams httpParams = httpClient.getParams();
    ConnectivityManager connectivity = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo nwInfo = connectivity.getActiveNetworkInfo();
    if (nwInfo == null) {
        return;
    }
    Log.i(LOG_TAG, nwInfo.toString());
    if (nwInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
        String proxyHost = Proxy.getHost(context);
        if (proxyHost == null) {
            proxyHost = Proxy.getDefaultHost();
        }
        int proxyPort = Proxy.getPort(context);
        if (proxyPort == -1) {
            proxyPort = Proxy.getDefaultPort();
        }
        if (proxyHost != null && proxyPort > -1) {
            HttpHost proxy = new HttpHost(proxyHost, proxyPort);
            httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        } else {
            httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null);
        }
    } else {
        httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null);
    }
}

From source file:com.OpenSource.engine.connectivity.ConnectivityInfoProvider.java

private void notifyListeners(NetworkInfo networkInfo) {
    if (connectivityListenersList != null) {
        for (IConnectivityListener connectivityListener : connectivityListenersList) {
            switch (networkInfo.getState()) {
            case CONNECTED:
                connectivityListener.onConnected(networkInfo.getType());
                if (networkInfo.isRoaming()) {
                    connectivityListener.onRoaming();
                }/*from   w  w  w.j a  va 2s  . c o  m*/
                break;
            case CONNECTING:
                connectivityListener.onConnecting(networkInfo.getType());
                break;
            case DISCONNECTED:
                connectivityListener.onDisconnected(networkInfo.getType());
                break;
            case DISCONNECTING:
                connectivityListener.onDisconnecting(networkInfo.getType());
                break;
            case UNKNOWN:
                break;
            }
        }
    }
}

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 {/*ww  w  .jav  a  2 s  .  c om*/
        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:org.pidome.client.phone.services.SystemService.java

private void setHome() {
    if (prefs != null) {
        if (prefs.getBoolPreference("wifiConnectHomeEnabled", false)) {
            ConnectivityManager connManager = (ConnectivityManager) getSystemService(
                    Context.CONNECTIVITY_SERVICE);
            NetworkInfo networkInfo = connManager.getActiveNetworkInfo();
            if (networkInfo.isConnected() && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
                final WifiInfo connectionInfo = wifiManager.getConnectionInfo();
                if (connectionInfo != null) {
                    String SSID = connectionInfo.getSSID();
                    String BSSID = connectionInfo.getBSSID();
                    if (SSID != null && BSSID != null) {
                        if (SSID.equals(prefs.getStringPreference("wifiConnectSSID",
                                java.util.UUID.randomUUID().toString()))
                                && BSSID.equals(prefs.getStringPreference("wifiConnectBSSID",
                                        java.util.UUID.randomUUID().toString()))) {
                            if (this.system != null) {
                                try {
                                    system.getClient().getEntities().getPresenceService().setPresence(1);
                                } catch (EntityNotAvailableException ex) {
                                    Logger.getLogger(SystemService.class.getName()).log(Level.SEVERE, null, ex);
                                }/*  ww  w.j  av  a  2  s  .  c om*/
                            }
                        }
                    }
                }
            }
        }
    }
}

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 a v 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;

}