by sashishk on Thu Sep 17, 2009 2:04 am
Hey Marcus,
The HTTPConnectionFactory class is wonderful implementation. I've included this into my code. I'm calling the connection factory as in below attached code:
String hitURL(String url)
{
HttpConnectionFactory factory = new HttpConnectionFactory(url, HttpConnectionFactory.TRANSPORTS_ANY);
String message = "";
while( true )
{
try
{
HttpConnection connection = factory.getNextConnection();
try
{
connection.setRequestMethod( "GET" );
InputStream input = connection.openInputStream();
.........get data from stream........
message = data fetched;
input.close();
break;
}
catch( IOException e)
{
try
{
connection.close();
}
catch(IOException e1){}
//Log the error or store it for displaying to the end user if no transports succeed
//Note you should never attempt network activity on the event thread
Dialog.alert( "Unable to perform request!!!" );
}
}
catch(NoMoreTransportsException e)
{
//There are no more transports to attempt
//Note you should never attempt network activity on the event thread
Dialog.alert( "No more transports available...."+e.toString());
break;
}
}
return message;
}
It works well but sometimes on device and simulator, when I try to make a call to internet, it gets hanged. Following are the differences w.r.t the code you have put on public domain for usage of the connection factory.
1) GET used instead on POST
2) In case of exception I have given dialog alert after closing the connection
Please suggest if the above changes can cause the app to be in hang state if I use post, or is Dialog is shown in case of exception.
How can I know if the signal strength has gone down during the course of fetching the data after the connection was established?
Thanks
-aks