How can I determine the current internet connection type available to an Android device? e.g. have it return WiFi, 3G, none.
相关问题
- 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 also use the TelephonyManager to find out what the mobile network type is:
Possible network types are listed at http://developer.android.com/reference/android/telephony/TelephonyManager.html#getNetworkType%28%29
You can use this to determine whether you are connected:
This code requires the permissions
ACCESS_NETWORK_STATE
andACCESS_WIFI_STATE
.EDIT:
public NetworkInfo getNetworkInfo (int networkType)
has been deprecated in API 21. For API levels higher than 20 you can do as follows:I limited this code to Wi-Fi and 3G as per the OP's question but it's easy to extend it to newly added connection types such as Ethernet or Wi-Max.
see this post, I answered the same question how to save request and resend in android app
Don't know why your app crashes, maybe this helps. Maybe try this method: (needs the application context)
then try to call
hope this helps