Well, I'm not too familiar with the apache packages. I've been using
the java.net classes instead. Typical code looks like this:
URL url;
// ...
HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
urlc.setRequestProperty("User-Agent", "My Android Demo");
urlc.setRequestProperty("Connection", "close");
urlc.setConnectTimeout(1000 * mTimeout); // mTimeout is in seconds
urlc.connect();
if (urlc.getResponseCode() == 200) {
// all is well
InputStream is = urlc.getInputStream();
// ...
} else {
// oops
}
That seems to work just fine for me. There are lots of examples on the
web of how to use the java.net classes to post, and setting the
connection timeout should work pretty much the same.
There may be other classes
Good luck.
On Mar 31, 6:27 am, alvin <[EMAIL PROTECTED]> wrote:
> HiTed,
>
> Thanks for your help. I really appreciate it. I have a couple of
> issues:
>
> 1) I used an HttpConnection to open a connection. And by calling the
> method .getConnectionWithTimeout (host, timeout) I can get the
> connection to timeout. HOWEVER, I performed a test where I open the
> connection WITH internet FIRST, then I disable my internet, and run it
> AGAIN. This results in the connection taking forever to break out.
> EVENTUALLY it does break out (after about 3 or 4 minutes). This isn't
> exactly ideal. I feel like it resets to default or the connection
> maintains some sort of persistent state. I have no idea why it doesn't
> "refresh" itself and time out like it's supposed to.
>
> 2) In another part of my code, I try to post some data to a server
> using HttpClient.execute(HttpPost) [in the
> org.apache.http.client.HttpClient package]. I have no idea how to time
> this out. There doesn't seem to be any methods associated with
> httpclient to set a timeout characteristic.
>
> Any help would be appreciated. I've also been looking into
> datastateintentreceiver, except there is very little documentation on
> it and I think that might be useful. Thanks in advanced.
>
> On Mar 30, 11:06 pm,TedHopp<[EMAIL PROTECTED]> wrote:
>
> > You can call setConnectTimeout() before making the connection. If
> > there is no internet connection, the response code should be -1. (Note
> > that the default timeout is 0, which means that your connection will
> > wait forever for a response.)
>
> >TedHopp
>
> > On Mar 30, 7:17 am, aTai <[EMAIL PROTECTED]> wrote:
>
> > > How do I check whether the phone/emulator is connected to the
> > > internet?
>
> > > I'm trying to connect with a server, and I need to figure out how to
> > > detect whether I have connectivity. Is there any way to do this on
> > > android?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---