Android Open Source - gm-httpengine-eclipse G M Net State Manager






From Project

Back to project page gm-httpengine-eclipse.

License

The source code is released under:

MIT License

If you think the Android project gm-httpengine-eclipse listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.gemini.net;
// ww  w  .  j a v a 2  s  .com
import org.apache.http.HttpHost;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;

/**
 * 
 * @author luopeng (luopeng@staff.sina.com.cn)
 */
public class GMNetStateManager {
  private static Context sContext;

  public static NetState CUR_NETSTATE = NetState.Mobile;

  public enum NetState {
    Mobile, WIFI, NOWAY
  }

  public class NetStateReceive extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
      sContext = context;
      if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
        WifiManager wifiManager = (WifiManager) context
            .getSystemService(Context.WIFI_SERVICE);
        WifiInfo info = wifiManager.getConnectionInfo();
        if (!wifiManager.isWifiEnabled() || -1 == info.getNetworkId()) {
          CUR_NETSTATE = NetState.Mobile;
        }
      }
    }

  }

  public static HttpHost getAPN() {
    HttpHost proxy = null;
    Uri uri = Uri.parse("content://telephony/carriers/preferapn");
    Cursor cursor = null;
    if (null != sContext) {
      cursor = sContext.getContentResolver().query(uri, null, null, null, null);
    }
    if (cursor != null && cursor.moveToFirst()) {
      String proxyStr = cursor.getString(cursor.getColumnIndex("proxy"));
      if (proxyStr != null && proxyStr.trim().length() > 0) {
        proxy = new HttpHost(proxyStr, 80);
      }
      cursor.close();
    }
    return proxy;
  }
}




Java Source Code List

org.gemini.listener.OnProgressUpdateListener.java
org.gemini.listener.OnResponseListener.java
org.gemini.net.GMHttpEngine.java
org.gemini.net.GMHttpParameters.java
org.gemini.net.GMHttpRequest.java
org.gemini.net.GMHttpResponse.java
org.gemini.net.GMHttpService.java
org.gemini.net.GMNetStateManager.java
org.gemini.parser.DefaultHttpRequestParser.java
org.gemini.parser.HttpRequestParser.java
org.gemini.parser.HttpResponseParser.java
org.gemini.util.LOG.java