• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Porblem in identifying Network Availability

 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 51
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Hardik Trivedi
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
F8 works

Thanks a lot dave :-)
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic