android.permission.ACCESS_WIFI_STATE

view Wi-Fi status

Allows an application to view the information about the status of Wi-Fi.

Protection level: normal

Constant Value: "android.permission.ACCESS_WIFI_STATE"

1
<uses-permission android:name="com.android.alarm.permission.ACCESS_WIFI_STATE" />

Added in API level 1

Sample code snippet:

1
2
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();

Failure to declare the permission will lead to app crash with following exception:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
FATAL EXCEPTION: main
Process: com.thecoderok.myapplication, PID: 11884
java.lang.SecurityException: WifiService: Neither user 10091 nor current process has android.permission.ACCESS_WIFI_STATE.
at android.os.Parcel.readException(Parcel.java:1942)
at android.os.Parcel.readException(Parcel.java:1888)
at android.net.wifi.IWifiManager$Stub$Proxy.getConnectionInfo(IWifiManager.java:1239)
at android.net.wifi.WifiManager.getConnectionInfo(WifiManager.java:1609)
at com.thecoderok.myapplication.MainActivity$2.onClick(MainActivity.java:50)
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24697)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

Related: