How to check that network is available or not on android device programmatically, which throws a message or toast message when we are trying to connect with a network such as Wifi & 3G.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
You can use this method to check whether your internet connection is 2G, 3G or 4G:
And using following method you can check if internet is available or not, and get whether you are accessing the internet via a mobile network or WiFi:
Rahul Baradia's answer includes
manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
and it's deprecated.Below is an improved solution for the latest Android SDK.
this code check if you are with wifi or 3g or nothing , in the case of wifi on but not connected to a net or 3g have signal problem it detect this details, with DetailedStates
in none of the code above i see a check for whether getNetworkInfo() returned null, which happens according to the docs when the requested network type is not supported. this suggests that on devices without 3g the app will crash with null pointer exception.
This work for me