When the connectivity changes, some (it seems most) firmwares
force-close any currently open connections, but some do not (two
examples: Motorola Milestone with 2.1, and a much more recent HTC
Incredible S with 2.3...).
Given the latter, I, too, had to implement code to close and reopen
TCP/IP sockets upon connectivity changes.
On the surface, it's pretty simple: just watch for CONNECTIVITY_ACTION.
But, as it often happens, it's complicated by various device- and
firmware- specific .... erm... quirks...
In particular, I've seen firmwares send a DISCONNECT event for a
connection type that was disabled a long time ago (like, disconnect
Mobile, connect WiFi, then five minutes later - hey, we're disconnected
from Mobile, really). I've seen a CONNECT event for WiFi being sent
twice when swtiching from Mobile, the first time being before the new
connection is usable.
CONNECTIVITY_ACTION events are also sent for network types that have
nothing to do with general purpose Internet connectivity, such as
TYPE_SUPL which can come and go without affecting the Internet.
So, to summarize:
1) you're on the right track with CONNECTIVITY_ACTION but expect to do a
lot of testing and debugging before it really works.
2) based on my experience, watching WifiManager events isn't necessary
to detect general purpose connectivty changes.
And finally, if your code misses messages, it means that your
store-and-send logic isn't implemented correctly. Debug and fix it.
-- K
On 03/28/2012 02:57 PM, <Hera> wrote:
favorite
share [g+] share [fb] share [tw]
Hello,
My application has to open a socket and send/receive some message to
the server. This works fine but the problem is when I move inside the
building, then the device changes from one access points to the other
(same wifi network). In that moment, I have (1) to store the messages,
(2) create again the socket and (3) send stored messages. I not able
to recognize that moment and I am not storing all the messages. I
detect “A Connection timed out” exception in the BufferedReader and
then I start storing messages.
I have tried to detect that moment by this registering to this Intents
but I am still missing messages:
//To detect Connectivity changes.
cmIntent.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
cmReceiver = new connectionChangeReceiver();
context.registerReceiver(cmReceiver, cmIntent);
intentFilter intentFilter = new IntentFilter();
intentFilter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
intentFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
context.registerReceiver(cmReceiver, intentFilter);
Thank you so much
--
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]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en