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. cooliris PopupMenu

Can anyone tell me if there is a way to make a dialog show up on
android over a given position and look like the cartoon talk bubble
used in Gallery3D popupMenu without having to try to use and
understand many parts of that package. If I have a nine patch can I
use that to change the look of the dialog surrounding frame so that it
looks more like a cartoon talk bubble?

Thank you.

-- 

2. Max number of entries per table for SQLiteDatabase ontent provider

Hi,

I have an application that has a Content Provider with an
SQLiteDatabase. I noticed that

-- 

3. Call a static method from an AppWidget

4. What is different between @id/android:list and @+id/android:list ?

5. Samsung Galaxy Spica (I5700) Bluetooth SPP with Android 2.1

6. HELP: A Verizon Droid puzzle.

7. OpenglES issue with Acer liquid.