detecting network connections

by Faber Fedor » Mon, 02 Mar 2009 10:31:37 GMT


Sponsored Links
 I gave a presentation last week on my Android app and when I pushed the
Magic Button, nothing happened.  On my way home, I realized that I had
neglected to connect to the local WiFi. So, to avoid that ind of
embarrassment again  I need to detect whether or not I currently have a
network connection.  If I don't, I'd like my program to offer a list of
available network connections to choose from.

This can probably be done using the system services, but I can't find the
magic Google phrase that will show me how.

Any suggestions?

-- 

Faber Fedor
Linux New Jersey
 http://linuxnj.com 
faberfedor.blogspot.com

--~--~---------~--~----~------------~-------~--~----~



detecting network connections

by Mark Murphy » Mon, 02 Mar 2009 10:42:48 GMT


 


The android.net package is probably your friend, at least for the first
part.

ConnectivityManager#getActiveNetworkInfo() returns a NetworkInfo.
NetworkInfo#getState() will tell you if you are CONNECTED.

On the second part, I'd find the Intent that launches the wireless
settings activity and just use that.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
_The Busy Coder's Guide to Android Development_ Version 2.0 Published!

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


detecting network connections

by Faber Fedor » Mon, 02 Mar 2009 12:15:03 GMT


 




Sweet! (I've got to look up what # means in Java.)




That's what I was thinking.  How do I find that Intent?

BTW, I used Droidex to show off my app.  It worked very well, although the
audience wasn't all that impressed; they didn't realize how cool Droidex is
(they are a Cloud Computing (read: non-Android) group).  I expect the next
group (the NYC Android Developer's Group) to be duly impressed.  I'll let
you know. :-)


-- 

Faber Fedor
Linux New Jersey
 http://linuxnj.com 
faberfedor.blogspot.com

--~--~---------~--~----~------------~-------~--~----~



detecting network connections

by Mark Murphy » Mon, 02 Mar 2009 21:40:24 GMT


 


Sorry -- instance method.


*shrug*

Maybe look at the source code to AnyCut. I have a desktop icon for the
wireless settings activity through it, so maybe it has that baked in
somewhere.


Glad to hear it worked!

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
_The Busy Coder's Guide to Android Development_ Version 2.0 Published!

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. about creating tables

How can i create two tables in single database successfully.

plz suggest any easiest way to create it.....

-- 

2. Androit jayapura

Ngak. Ada kah andoid mania jayapura ???



-- 
"

3. Image Displayed Two Times

4. PhoneGap Camera app

5. What does this mean: Failure [INSTALL_FAILED_CONTAINER_ERROR] ?

6. Testing K9

7. Source for aOS 3 compatibility library