Skip to content

Instantly share code, notes, and snippets.

@kailash09dabhi
Last active July 20, 2016 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kailash09dabhi/724c3e1c4d6144ecbe25567c31524497 to your computer and use it in GitHub Desktop.
Save kailash09dabhi/724c3e1c4d6144ecbe25567c31524497 to your computer and use it in GitHub Desktop.
Check if internet is available or not
/*
* Copyright (C) 2016 Kailash Dabhi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
/**
* Created by Kailash Dabhi on 10-07-2016.
* You can contact us at kailash09dabhi@gmail.com OR on skype(kailash.09)
* Copyright (c) 2016 Kingbull Technology. All rights reserved.
*/
public class Internet {
private static Internet internet;
Context context;
Internet(Context context) {
this.context = context;
}
public static Internet instance(Context context) {
if (internet == null)
internet = new Internet(context);
return internet;
}
NetworkInfo networkInfo() {
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
return cm.getActiveNetworkInfo();
}
public boolean isAvailable() {
NetworkInfo info = internet.networkInfo();
return (info != null && info.isConnected());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment