Some time we need to check the availability of the network connection , with the help of this little code snippet we can check that the network is available or not, before using the the network interaction!!
public static String getTransports() {
avail = "notavailable";
_transportsWithCoverage = TransportInfo.getCoverageStatus();
_transports = TransportInfo
.getTransportDescriptors(_transportsWithCoverage);
for (int i = _transports.length - 1; i >= 0; --i) {
switch (_transports[i].getTransportType()) {
case TransportInfo.TRANSPORT_BIS_B: {
avail = "available";
return avail;
}
case TransportInfo.TRANSPORT_MDS: {
avail = "available";
return avail;
}
case TransportInfo.TRANSPORT_TCP_CELLULAR: {
avail = "available";
return avail;
}
case TransportInfo.TRANSPORT_TCP_WIFI: {
avail = "available";
return avail;
}
case TransportInfo.TRANSPORT_WAP: {
avail = "available";
return avail;
}
case TransportInfo.TRANSPORT_WAP2: {
avail = "available";
return avail;
}
}
}
return avail;
}
No comments:
Post a Comment