Example usage for android.net ConnectivityManager TYPE_WIFI

List of usage examples for android.net ConnectivityManager TYPE_WIFI

Introduction

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

Prototype

int TYPE_WIFI

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

Click Source Link

Document

A WIFI data connection.

Usage

From source file:crow.util.Util.java

/**
 * ??wifi//from www .j a v a 2s  .  com
 * 
 * @param context
 * @return true ?wifi false 
 */
public static boolean isWifi(Context context) {
    ConnectivityManager connManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = connManager.getActiveNetworkInfo();
    if (netInfo != null) {
        int type = netInfo.getType();
        if (type == ConnectivityManager.TYPE_WIFI) {
            return true;
        }
    }
    return false;
}

From source file:org.ocs.android.agent.service.OCSAgentService.java

private boolean isOnline() {
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnectedOrConnecting()) {
        if (mOcssetting.getAutoModeNetwork() == AUTOMODE_NOROAMING && !netInfo.isRoaming()) {
            return true; // no roaming
        }/*from ww  w  .  j  av a2  s. c  om*/
        if (mOcssetting.getAutoModeNetwork() == AUTOMODE_ANY) {
            return true; // any network (including roaming)
        }
        if (mOcssetting.getAutoModeNetwork() == AUTOMODE_WIFI
                && netInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            return true; // wifi only
        }
    }
    return false;
}

From source file:org.mycard.net.network.RequestQueue.java

/***
 * Because our IntentReceiver can run within a different thread,
 * synchronize setting the proxy//w w  w  .ja  va2s  . co  m
 */
@SuppressWarnings("deprecation")
private synchronized void setProxyConfig() {
    NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
    if (info != null && info.getType() == ConnectivityManager.TYPE_WIFI) {
        mProxyHost = null;
    } else {
        String host = System.getProperty("http.proxyHost");
        String portStr = System.getProperty("http.proxyPort");
        int port = Integer.parseInt((portStr != null ? portStr : "-1"));

        if (TextUtils.isEmpty(host) || port <= 0) {
            host = android.net.Proxy.getHost(mContext);
            port = android.net.Proxy.getPort(mContext);
        }

        if (TextUtils.isEmpty(host) || port <= 0) {
            mProxyHost = null;
        } else {
            mActivePool.disablePersistence();
            mProxyHost = new HttpHost(host, port, "http");
        }
    }
}

From source file:com.fanfou.app.opensource.util.NetworkHelper.java

public static final boolean isWifi(final Context context) {
    final ConnectivityManager connec = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo info = connec.getActiveNetworkInfo();
    return (info != null) && (info.getType() == ConnectivityManager.TYPE_WIFI);
}

From source file:jupiter.broadcasting.live.holo.JBPlayer.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Context ct = this;
    String ns = NOTIFICATION_SERVICE;
    mNotificationManager = (NotificationManager) getSystemService(ns);
    nReceiver = new BroadcastReceiver() {
        @Override/*w  w w  . j  a  v a 2 s.  c o  m*/
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action != null) {
                if (action.equalsIgnoreCase("PLAY_PAUSE")) {
                    if (mp.isPlaying()) {
                        mp.pause();
                        unregisterReceiver(nReceiver);
                        putNotificationUp(mp.isPlaying());
                    } else {
                        mp.start();
                        unregisterReceiver(nReceiver);
                        putNotificationUp(mp.isPlaying());
                    }
                } else if (action.equalsIgnoreCase("STOP")) {
                    unregisterReceiver(nReceiver);
                    mNotificationManager.cancel(NOTIFICATION_ID);
                    mp.stop();
                    start = false;
                }
            }
        }
    };

    //check if network notification is disabled in settings
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    notify = sharedPref.getBoolean("pref_sync_audio", false);

    mVideoCastManager = JBApplication.getVideoCastManager(this);
    mVideoCastManager.reconnectSessionIfPossible(this, true);

    supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.mediaplayer);

    type = getIntent().getIntExtra("type", 3);
    title = getIntent().getStringExtra("title");
    pic = "http://jb4.cdn.scaleengine.net/wp-content/themes/jb2014/images/logo.png";
    hasit = HasIt(title, av);
    getSupportActionBar().setTitle(title);
    mDecorView = getWindow().getDecorView();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
        mDecorView.setOnSystemUiVisibilityChangeListener(this);

    // going on different routes if coming from Catalogue/Home/EpisodeList
    offline = getIntent().getBooleanExtra("offline", false);
    String help = getIntent().getStringExtra("loc");
    live = ((help != null) && help.equalsIgnoreCase("-1"));
    if (!offline && !hasit) {
        pic = getIntent().getStringExtra("pic");
        aLink = getIntent().getStringExtra("aLink");
        vLink = getIntent().getStringExtra("vLink");
        theLink = aLink;
        GetSize newSize = new GetSize();
        newSize.execute();
    } else if (!live) {
        theLink = getIntent().getStringExtra("loc");
    } else {
        aLink = getIntent().getStringExtra("aLink");
        vLink = getIntent().getStringExtra("vLink");
        theLink = aLink;
    }

    iView = (FadeImageView) findViewById(R.id.thumb);
    RequestQueue mReqQue = Volley.newRequestQueue(getApplicationContext());
    ImageLoader mImageLoader = new ImageLoader(mReqQue, new BitmapLruCache());

    if (!offline) {
        iView.setImageUrl(pic, mImageLoader);
    }
    if (offline && !live) {
        switch (type) {
        case 0:
            SpinnerArray.add(getString(R.string.audio));
            break;
        case 1:
            SpinnerArray.add(getString(R.string.video));
            break;
        }
    } else {
        SpinnerArray.add(getString(R.string.audio));
        SpinnerArray.add(getString(R.string.video));
    }
    spinner = (Spinner) findViewById(R.id.AV);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            SpinnerArray);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(this);

    tw = (TextView) findViewById(R.id.summary);
    tw.setMovementMethod(new ScrollingMovementMethod());
    tw.setText(getIntent().getStringExtra("sum"));

    play = (Button) findViewById(R.id.player);
    play.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            ConnectivityManager connectivity = (ConnectivityManager) getSystemService(
                    Context.CONNECTIVITY_SERVICE);
            wifiInfo = connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
            if ((wifiInfo == null || wifiInfo.getState() != NetworkInfo.State.CONNECTED) && !hasit && notify) {
                AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(ct);
                myAlertDialog.setTitle(R.string.alert);
                myAlertDialog.setMessage(R.string.areyousure2);
                myAlertDialog.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface arg0, int arg1) {
                        if (av == 1) //video
                            StartPlay(theLink);
                        else //audio
                            try {
                                StartPlayBackground(theLink);
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                    }
                });
                myAlertDialog.setNegativeButton(getString(R.string.cancel),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface arg0, int arg1) {
                            }
                        });
                myAlertDialog.show();
            } else {
                if (av == 1) //video
                    StartPlay(theLink);
                else //audio
                    try {
                        StartPlayBackground(theLink);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
            }

        }
    });

    down = (Button) findViewById(R.id.downer);
    if (offline || hasit) {
        down.setVisibility(View.INVISIBLE);
    }
    down.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            final String url = theLink;
            //if wifi not connected, ask to make sure
            ConnectivityManager connectivity = (ConnectivityManager) getSystemService(
                    Context.CONNECTIVITY_SERVICE);
            wifiInfo = connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
            if ((wifiInfo == null || wifiInfo.getState() != NetworkInfo.State.CONNECTED) && notify) {
                AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(ct);
                myAlertDialog.setTitle(R.string.alert);
                myAlertDialog.setMessage(R.string.areyousure2);
                myAlertDialog.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface arg0, int arg1) {
                        DownLoad(url);
                    }
                });
                myAlertDialog.setNegativeButton(getString(R.string.cancel),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface arg0, int arg1) {
                            }
                        });
                myAlertDialog.show();
            } else {
                DownLoad(url);
            }

        }
    });
}

From source file:org.restcomm.app.utillib.DataObjects.PhoneState.java

public static int ActiveConnection(Context context) {
    try {/*from w w  w  . j  ava2  s  .c om*/
        ConnectivityManager connectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivityManager != null) {
            NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
            if (networkInfo != null) {
                int wifiState = networkInfo.getType();
                if (wifiState == ConnectivityManager.TYPE_WIFI)
                    return 10;
                else if (wifiState == PhoneState.TYPE_WIMAX)
                    return 11;
                else if (wifiState == PhoneState.TYPE_ETHERNET)
                    return 12;
                else if (wifiState == PhoneState.TYPE_BLUETOOTH)
                    return 13;
            }
        }
    } catch (Exception e) {
        return -1;
    }
    return 0;
}

From source file:com.photowall.oauth.util.BaseHttpClient.java

/**
 * ??WiFi/*from   w  w w.  j  a va 2s  .  c  o m*/
 * @param mContext
 * @return
 */
private boolean isWiFiConnected(Context mContext) {
    boolean isWifiEnable = false;
    ConnectivityManager connectivityManager = (ConnectivityManager) mContext
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
    if (activeNetInfo != null && activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI) {
        isWifiEnable = true;
    }
    return isWifiEnable;
}

From source file:pubsub.io.android.Pubsub.java

/**
 * Detects if we have internet or not, checks both WiFi and 3G.
 * /*w w w .ja  v a  2s  .co m*/
 * @return
 */
public boolean hasInternet() {
    if (DEBUG)
        Log.i(TAG, "hasInternet()");

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

    if (DEBUG)
        Log.i(TAG, "Testing WiFi status");

    // First test wifi for status!
    NetworkInfo netInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (netInfo != null && netInfo.isConnectedOrConnecting()) {
        if (DEBUG)
            Log.i(TAG, "WiFi detected, connecting");
        return true;
    }

    if (DEBUG)
        Log.i(TAG, "No WiFi detected, trying mobile");

    netInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (netInfo != null && netInfo.isConnectedOrConnecting()) {
        if (DEBUG)
            Log.i(TAG, "Mobile detected, connecting");
        return true;
    }

    if (DEBUG)
        Log.i(TAG, "No Mobile detected, aborting");

    return false;
}

From source file:org.odk.collect.android.upload.AutoSendWorker.java

/**
 * Returns whether the currently-available connection type is included in the app-level auto-send
 * settings./*from  w ww .  java2  s . co m*/
 *
 * @return true if a connection is available and settings specify it should trigger auto-send,
 * false otherwise.
 */
private boolean networkTypeMatchesAutoSendSetting(NetworkInfo currentNetworkInfo) {
    if (currentNetworkInfo == null) {
        return false;
    }

    String autosend = (String) GeneralSharedPreferences.getInstance().get(PreferenceKeys.KEY_AUTOSEND);
    boolean sendwifi = autosend.equals("wifi_only");
    boolean sendnetwork = autosend.equals("cellular_only");
    if (autosend.equals("wifi_and_cellular")) {
        sendwifi = true;
        sendnetwork = true;
    }

    return currentNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI && sendwifi
            || currentNetworkInfo.getType() == ConnectivityManager.TYPE_MOBILE && sendnetwork;
}