03-21-2012 04:23 PM
Hi I am using this rotuine to check if my app has internet access to conect to some web services.
public static boolean isInternetAvailable() {
boolean result = false;
// Toma transportes disponibles
int[] transportArray = TransportInfo.getAvailableTransportTypes();
for (int i = transportArray.length - 1; i > - 1; i--) {
if (TransportInfo.hasSufficientCoverage(i)) {
result = true;
break;
}
}
return result;
}
But this code sometimes work. I am running in the simulator (and phones, specially with OS 7) and I am positive I have network acess, however the method return false sometimes...
Is there another safer way to check this ?
Solved! Go to Solution.
03-21-2012 05:57 PM
After a check, the problem is with version 7.0. 5.0 and 6 works fine.
Must use Manage Connection to reset Mobile NetWork and WI-FI.
Then I call two web services (in this case they are in tah same server). My result are :
5.0
Transporte WIFI
http://XXX.XXX.XXX.XXX/MyWebService.asmx;devicesid
Response OK
Transporte WIFI
http://XXX.XXX.XXX.XXX/MyWebService.asmx2;devicesi
Response OK
--------------------------------------------------
7.0
Erratic - Must use Manage Connection to reset Mobile NetWork and WI-FI
Transporte WIFI
http://XXX.XXX.XXX.XXX/MyWebService.asmx;devicesid
Response OK
Transporte WIFI
http://XXX.XXX.XXX.XXX/MyWebService.asmx2;devicesi
Time out...
Note than in the second call it does not recognize that I running this app in the simulator..!!!!
My code to get the available transpor is :
String url = mUrl;
ConnectionFactory cf = new MyConnectionFactory();
ConnectionDescriptor cd = cf.getConnection(url);
url = cd.getUrl();
mHttpTransport = new HttpTransport(url);
mHttpTransport.call(mSoapAction, mEnvelope);
Object response = mEnvelope.getResponse();
mResponse = response.toString().trim();
....
class MyConnectionFactory extends ConnectionFactory {
public MyConnectionFactory() {
setPreferredTransportTypes(new int[] {
TransportInfo.TRANSPORT_TCP_WIFI,
TransportInfo.TRANSPORT_MDS,
TransportInfo.TRANSPORT_TCP_CELLULAR,
TransportInfo.TRANSPORT_WAP2 });
setDisallowedTransportTypes(new int[] {
TransportInfo.TRANSPORT_WAP, TransportInfo.TRANSPORT_BIS_B });
setAttemptsLimit(10);
setConnectionTimeout(10000);
setTimeLimit(10000);
}
}
Is there a special treatment for OS 7 or something is wrong in my code ?
TIA
03-22-2012 03:40 AM
03-22-2012 10:15 AM
Thanks Simon.
I rewrote my code to :
public static boolean isInternetAvailable() {
boolean result = false;
int[] coverageArray = { CoverageInfo.COVERAGE_BIS_B,
CoverageInfo.COVERAGE_DIRECT, CoverageInfo.COVERAGE_MDS };
int[] wafArray = { RadioInfo.WAF_3GPP, RadioInfo.WAF_CDMA,
RadioInfo.WAF_IDEN, RadioInfo.WAF_WLAN };
int coverageLen = coverageArray.length;
int wafLen = wafArray.length;
for (int i=0; i < coverageLen && !result; i++) {
for (int j = 0; j < wafLen; j++) {
if (CoverageInfo.isCoverageSufficient(coverageArray[i ],
wafArray[j], false)) {
result = true;
break;
}
}
}
return result;
}
Is it OK ? It looks like it working fine now..
03-22-2012 10:27 AM
03-22-2012 10:47 AM
Simon, so just
public static boolean isInternetAvailable() {
return CoverageInfo.isCoverageSufficient(CoverageInfo.COV ERAGE_DIRECT);
}
It run fine...
Thanks a lot Simon...!!!!!
03-22-2012 11:07 AM