Android检查手机网络状态及网络类型的方法
程序员文章站
2022-06-23 10:17:15
本文实例讲述了android检查手机网络状态及网络类型的方法。分享给大家供大家参考。具体分析如下:
//judge network status is conne...
本文实例讲述了android检查手机网络状态及网络类型的方法。分享给大家供大家参考。具体分析如下:
//judge network status is connecting or not public static boolean checknetworkconnected(context context) { if (null!=context) { connectivitymanager connectivitymanager = (connectivitymanager) context .getsystemservice(context.connectivity_service); networkinfo networkinfo = connectivitymanager.getactivenetworkinfo(); if (null!=networkinfo) { return networkinfo.isavailable(); } } return false; } //judge wifi status is connecting or not public static boolean checkwifistatus(context context) { connectivitymanager connectivitymanager = (connectivitymanager) context .getsystemservice(context.connectivity_service); networkinfo networkinfo = connectivitymanager.getactivenetworkinfo(); if (null!=networkinfo && networkinfo.gettype() == connectivitymanager.type_wifi) { return true; } return false; } //judge 3g status is connecting or not public static boolean check3gstatus(context context) { connectivitymanager connectivitymanager = (connectivitymanager) context .getsystemservice(context.connectivity_service); networkinfo networkinfo = connectivitymanager.getactivenetworkinfo(); if (null!=networkinfo && networkinfo.gettype() == connectivitymanager.type_mobile) { return true; } return false; }
希望本文所述对大家的android程序设计有所帮助。
上一篇: 使用springboot暴露oracle数据接口的问题
下一篇: Android编程之蓝牙测试实例