-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisInternetAvailable.java
More file actions
44 lines (40 loc) · 1.41 KB
/
Copy pathisInternetAvailable.java
File metadata and controls
44 lines (40 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* Created by ROYALRandhawa
* Github @ROYALRandhawa
* Freelancer @ROYALRandhawa
* ---------------------------------------------------------------
* SUPPORT US ON FACEBOOK -> https://fb.com/imroyalrandhawa
* TWITTER -> https://twitter.com/@imroyalrandhawa
* ---------------------------------------------------------------
* Support Our Effort With PayPal -> https://paypal.me/royalrandhawa
*
*
* Following Codes Check Both Mobile Network and WiFi.
* How To Use:
* if(new Helper().isNetworkAvailable()){
* //Network Available
* }else{
* //Network Not Available
* }
*
*/
public class Helper extends Activity {
private boolean isNetworkAvailable() {
boolean haveConnectedWifi = false;
boolean haveConnectedMobile = false;
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] netInfo = new NetworkInfo[0];
if (cm != null) {
netInfo = cm.getAllNetworkInfo();
}
for (NetworkInfo ni : netInfo) {
if (ni.getTypeName().equalsIgnoreCase("WIFI"))
if (ni.isConnected())
haveConnectedWifi = true;
if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
if (ni.isConnected())
haveConnectedMobile = true;
}
return haveConnectedWifi || haveConnectedMobile;
}
}