Android判断是否有网络
16lz
2021-01-23
广播实现,起到提示用户作用public void onReceive(Context context, Intent intent) { //通过getSystemService()方法得到connectionManager这个系统服务类,专门用于管理网络连接 ConnectivityManager connectionManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectionManager.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isAvailable()) { Toast.makeText(context, "网络可用", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(context, "网络不可用", Toast.LENGTH_SHORT).show(); }}
更多相关文章
- 设置里首选网络类型由3G改成4G
- android 使用Http的POST方式读取网络数据
- android 网络请求get,post实现
- Android判断是否有可用网络和判断WIFI是否ON
- Android 登陆、提交数据或者加载数据时提示页面
- Android http 网络框架对比
- Android中的http网络通信基础点