Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static boolean isNetworkAvailable(Context context) {
- ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
- NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
- if (activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting()) {
- new AsyncTask<Void, Void, Boolean>() {
- @Override
- protected Boolean doInBackground(Void... params) {
- boolean internetStatus = false;
- HttpURLConnection urlc = null;
- try {
- urlc = (HttpURLConnection) (new URL("http://www.google.com").openConnection());
- urlc.setRequestProperty("User-Agent", "Test");
- urlc.setRequestProperty("Connection", "close");
- urlc.setConnectTimeout(1500);
- urlc.connect();
- Log.d(TAG, "GOOGLE LOADED SUCESSFULLY");
- if (urlc.getResponseCode() == 200) {
- internetStatus = true;
- } else
- internetStatus = false;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return internetStatus;
- }
- }.execute();
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement