• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Porblem in identifying Network Availability

 
Hardik Trivedi
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • 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.
 
Dave MacLean
author
Ranch Hand
Posts: 49
Android Java
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
F8 works

Thanks a lot dave :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic