37

What's the difference between ACCESS_NETWORK_STATE and INTERNET?

If I use INTERNET, is it necessary to use ACCESS_NETWORK_STATE?

In other words, can I use INTERNET without using ACCESS_NETWORK_STATE?

Alexandre Khoury
  • 3,896
  • 5
  • 37
  • 58
  • 6
    [INTERNET](http://developer.android.com/reference/android/Manifest.permission.html#INTERNET) and [ACCESS_NETWORK_STATE](http://developer.android.com/reference/android/Manifest.permission.html#ACCESS_NETWORK_STATE) – dymmeh Oct 28 '13 at 18:11

3 Answers3

47

From the documentation:

ACCESS_NETWORK_STATE:

Allows applications to access information about networks

INTERNET:

Allows applications to open network sockets.

In short, the INTERNET permission lets you use the internet, whereas ACCESS_NETWORK_STATE will just give you information about the network, such as whether you are connected to a network at all.

You can use either one without needing the other. If you don't check that you have a valid network connection before trying to use the Internet, your HTTP requests will simply fail.

Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120
11
android.permission.INTERNET

is enough if you just want to use internet (connect to a web service or show a web page on webView).

android.permission.ACCESS_NETWORK_STATE

is "nice to have" to query status of network state before using internet.

Devrim
  • 15,345
  • 4
  • 66
  • 74
  • Do you *have* to query the network state? Isn't it enough to catch the exception thrown when the HTTP request fails? – Dan Dascalescu Jan 07 '16 at 01:41
  • 5
    No you don't have to query network state. ACCESS_NETWORK usage case: At you application, you want to upload/download large amount of data and you prefer to do it when user is connected via wi-fi (you don't want to spend users mobile data packet), you can query connection status with this permission. – Devrim Jan 07 '16 at 07:40
3

INTERNET allows you to use the internet

ACCESS_NETWORK_STATE allows you to get the state of the network (wifi ,3g,4g) also you can check if the network is connected or not

If there is no internet the HTTP request will fail and you will get some sort of exception that you will have to handle

tyczj
  • 71,600
  • 54
  • 194
  • 296