I\'m trying to get the new ConnectivityManager.bindProcessToNetwork(Network)
using ConnectivityManager.requestNetwork(NetworkRequest, ConnectivityManager.Netw
I'm not sure if this was intended by Google, but the following is the behavior I'm seeing:
CHANGE_NETWORK_STATE
seems to always be denied (as noted in the comments, its a signature permission) but it also doesn't seem to matter. My ConnectivityManager
network requests all seem to be gated by WRITE_SETTINGS
only - so if you have WRITE_SETTINGS
you don't need CHANGE_NETWORK_STATE
.
As noted in comments, you do this differently than other permissions, using:
Intent goToSettings = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
goToSettings.setData(Uri.parse("package:" + Context.getPackageName()));
startActivity(goToSettings);
And after that, my ConnectivityManager
network requests were peachy.
To check if the permission is already granted before calling the ACTION_MANAGE_WRITE_SETTINGS
activity, this answer has the solution using
Settings.System.canWrite(Context)
Can't get WRITE_SETTINGS permission
UPDATE: as of Android 6.0.1, CHANGE_NETWORK_STATE
is auto granted when requested in your manifest file. The above WRITE_SETTINGS
checks are only required for 6.0