Search code examples
androidandroid-manifest

Fatal Exception: java.lang.SecurityException:: Neither user 10021 nor current process has android.permission.CHANGE_WIFI_STATE


I am getting this error

Fatal Exception: java.lang.SecurityException: InforService: Neither user 10133 nor current process has android.permission.CHANGE_WIFI_STATE.
       at android.os.Parcel.createException(Parcel.java:1950)
       at android.os.Parcel.readException(Parcel.java:1918)
       at android.os.Parcel.readException(Parcel.java:1868)
       at android.net.wifi.InfoManager$Stub$Proxy.addOrUpdateNetwork(InfoManager.java:135)


Caused by android.os.RemoteException: Remote stack trace:
    at android.app.ContextImpl.enforce(ContextImpl.java:1812)
    at android.app.ContextImpl.enforceCallingOrSelfPermission(ContextImpl.java:1840)

manifest.xml has

 <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
  <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
  <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
  <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>

This error is currently happening on Android Operating system 8 and 9.

How can this be fix

Thanks


Solution

  • You cannot programmatically enable or disable wifi anymore For older devices do this:

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
        wifimanager.setWifiEnabled(false);
    }