File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Android and the fly likes Porblem in identifying Network Availability Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Mobile » Android
Reply Bookmark "Porblem in identifying Network Availability" Watch "Porblem in identifying Network Availability" New topic
Author

Porblem in identifying Network Availability

Hardik Trivedi
Ranch Hand

Joined: Jan 30, 2010
Posts: 252
Hi,

I want to know whether network is available or not.I googled and I found code snippet too.Below is the code I am using.



I am testing this in emulator. I turn off network too.

Code is returning true. It should return false.

Apart from this I tried many other code too.

Please reply where I am going wrong.
Dave MacLean
author
Ranch Hand

Joined: May 10, 2011
Posts: 46

That should work in the emulator, but how are you turning the network off? Did you press the F8 key in the emulator?

Also, did you request the ACCESS_NETWORK_STATE permission in your AndroidManifest.xml file?

Lastly, you may want to use just isConnected() instead. The NetworkInfo may report true for isConnectedOrConnecting() when the network connections appear to be possible but even if you aren't able to use it yet. I also found a post that suggested using isAvailable() as well in your checks.

- dave

Dave MacLean our book (Pro Android 3)
Hardik Trivedi
Ranch Hand

Joined: Jan 30, 2010
Posts: 252
F8 works

Thanks a lot dave :-)
 
 
subject: Porblem in identifying Network Availability
 
Threads others viewed
Giving path alias to network folder in server.xml
Two network cards on linux
All of URLy Bird 1.1.3 how to use the same GUI and Data in alone or netword client
A Generics and Collections Problem
javax.xml.ws.WebServiceException: Failed to access the WSDL file and Server redirected too many time
MyEclipse, The Clear Choice

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture