Issue
In one of my Apps, I am changing WiFi State. Like this:
wifiManager.setWifiEnabled(false);
I have these permissions in manifest:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.UPDATE_DEVICE_STATS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
The code is working perfectly in my phone and most other phones. However, today I got crash report with following error:
Caused by: java.lang.SecurityException: NetworkManagementService: Neither user 10147 nor current process has android.permission.CHANGE_NETWORK_STATE.
The stack trace indicates that this error is caused by the line where I am changing the WiFi state unsig wifiManager.setWifiEnabled(false);
Why does this happen? How come it works with no issues in almost all devices and why did it crash in this particular case? Is it Android version or device dependent? Do I really need to add android.permission.CHANGE_NETWORK_STATE
permission just to change WiFi state?
Solution
The docs for CHANGE_NETWORK_STATE say Allows applications to change network connectivity state
so I would say, yeah, you do need to add the permission. Seems to me that disabling wi-fi would have a good chance of changing network state.
As for why it happened in this particular case, it could certainly be due to it running on a version of android that you haven't previously tested on.
Answered By - digitaljoel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.