What's the difference between ACCESS_NETWORK_STATE and INTERNET?

霸气de小男生 提交于 2019-12-04 09:56:01

问题


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?


回答1:


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.




回答2:


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.




回答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



来源:https://stackoverflow.com/questions/19642032/whats-the-difference-between-access-network-state-and-internet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!