public class NetUtil{private static String PROXY = "";      // 移动运营商代理: 中国移动:10.0.0.172 其它的忘了private static int PORT = 0;           // 端口:80/** * 检查用户网络 */public static boolean checkNet(Context context){// 判断WIFI连接boolean isWifi = isWifiConnection(context);// 判断Mobile连接boolean isMobile = isMobileConnection(context);// 如果Mobile连接,判断是哪个APN被选中了if(isMobile){// APN被选中,代理信息是否有内容,如果wap方式readAPN(context); // 判断是哪个APN被选中// TODO}if(!isWifi && !isMobile){return false;}return true;}/** * 读取被选中的APN * @param context */private static void readAPN(Context context) {// 操作联系人ContentResolver resolver = context.getContentResolver();Uri uri = Uri.parse("content://telephony/carriers/preferapn");Cursor cursor = resolver.query(uri, null, null, null, null);if(cursor!=null && cursor.moveToNext()){PROXY = cursor.getString(cursor.getColumnIndex("proxy"));PORT = cursor.getInt(cursor.getColumnIndex("port"));}}/** * 判断: Mobile连接 * @param context * @return */private static boolean isMobileConnection(Context context) {ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);NetworkInfo networkInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);if(networkInfo!=null){return networkInfo.isConnected();}return false;}/** * 判断: Wifi连接 * @param context * @return */private static boolean isWifiConnection(Context context) {ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);NetworkInfo networkInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);if(networkInfo!=null){return networkInfo.isConnected();}return false;}}

更多相关文章

  1. Android(安卓)热点开关状态的判断和获取热点ssid
  2. Android中判断网络功能是否可用
  3. Android的网络状态判断
  4. [android]在上下文菜单的选中事件中获取列表选中的元素
  5. Android,LIstView中的OnItemClick点击无效的解决办法
  6. Android打开/关闭数据流量
  7. 重定向android log
  8. Android(安卓)PureMVC
  9. 【android测试】值得学习的android测试知识连接

随机推荐

  1. android读写XML
  2. Android SurfaceView 的基本应用
  3. 改变ToggleButton的图片
  4. Android 文件存储 和 权限管理
  5. Android设置支持多种分辨率
  6. android中去掉listview某人选中高亮状态
  7. Android Debugging
  8. 【Android】Thread与Service的差异
  9. Android Studio常见问题
  10. android 支持宽屏