November 21, 2010

[SOLVED] How to check internet access on Android?

You can use
Context.getSystemService(Context.CONNECTIVITY_SERVICE).getNetworkInfo(ConnectivityManager.TYPE_MOBILE)

or
Context.getSystemService(Context.CONNECTIVITY_SERVICE).getNetworkInfo(ConnectivityManager.TYPE_WIFI)

and parse the DetailedState enum of the returned NetworkInfo object

 

and don't forget to allow it the Manifest

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

 

Source: stackoverflow.com

Documentation: http://developer.android.com/reference/android/net/ConnectivityManager.html

No comments:

Post a Comment