android用户网络检测工具
来源:互联网 发布:一知f君张碧晨 编辑:程序博客网 时间:2024/06/05 05:55
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;}}
0 0
- android用户网络检测工具
- 七牛android用户app端手机检测工具
- 网络检测工具 http socket
- 网络性能检测工具iperf
- android内存检测工具
- Android 调优:内存,检测工具
- Android 内存检测工具
- Android 内存检测工具
- Android性能优化检测工具
- android静态检测工具
- Android 性能指标检测工具
- Android 内存泄漏检测工具
- Android内存泄漏检测工具
- Android 性能检测工具
- Android 内存检测工具
- 一些常用的网络检测工具
- Ethereal(网络协议检测工具)
- netperf网络性能检测工具-嵌入式
- FlowVisor的学习笔记
- Redis常用命令解析——INFO, MONITOR, SLOWLOG
- Java基础之静态修饰符知识点总结
- C++: string的大小写转换
- Android中Context详解 ---- 你所不知道的Context
- android用户网络检测工具
- codevs1174 靶形数独(DLX)
- 位图初级(二)——相关数据结构
- oracle 11g AWR报告
- Git错误积累-持续更新
- HDU 5056: Boring count 枚举子串?不要急,一个一个来!
- 第26天 刷水题,好好锻炼
- 文件管理(一)创建并打开文件
- java-包的访问权限