Hey,
This code segment lets you check there is a network connection or not.
public boolean isNetworkConnected() { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); Log.d("MyApp", "Network Connection checking.."); NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); return activeNetworkInfo != null && activeNetworkInfo.isConnected(); }
If you need to check internet availability more than one places or more than one Activities, you’d better to create a Class which is InternetAvailability and use it via this class easily.Do not forget to add permission in AndroidManifest:<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
If you have a question, ask me :)