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. wbxml Parser available through IM app

Hi,

I am trying to use the library available in IM application to parse
the Wbxml data that I have.

I am able to parse the data only half the way because device info
parsing is not supported by the external library.

Even the page switching happens properly but when devinfo comes into
picture, it doesnot detect the binary data as valid tags. It even
doesnt shift the page when devinfo data is ready for parsing.

Am I correct?

Please respond.


Thanks
Praneeth

-- 

2. How to implement Calendar App in Android

Hi,

     I am working with Calendar functionality in android 2.2 api, and the api 
at that level (level 8) does not contain any Calendar classes to work for. so 
is there any way that i can implement calendar functionality?.

thanks & regards,
G.Santhosh Kumar

-- 

3. Paid promotions of my Application on Market

4. Call Skype

5. Berita Kehilangan HTC Desire Z

6. [WTA] Samsung Galaxy SL

7. [WTI] CyanogenMod 7 RC 1 Buat Spica Udah Di Release