Send request over WiFi (without connection) even if Mobile data is ON (with connection) on Android M : <p>I have to send UDP packets to a WiFi module (provided with own AP) with no internet connection but when I connect the mobile with the AP, Android redirects my packets on the mobile data interface because it has got internet connection.</p>

<p>I've used the code below to do my job but it seems not working on Android M.</p>

<pre><code>@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setWifiInterfaceAsDefault() {
    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkRequest.Builder builder = new NetworkRequest.Builder();
    NetworkRequest networkRequest= builder.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
            .addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
            .build();

    connectivityManager.requestNetwork(networkRequest, new ConnectivityManager.NetworkCallback());
}
</code></pre>

<p>I've also added</p>

<pre><code>&lt;uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /&gt;
&lt;uses-permission android:name="android.permission.WRITE_SETTINGS" /&gt;
</code></pre>

<p>on my AndroidManifest.xml and I ensured myself that <code>Settings.System.canWrite(this)</code> returns <code>true</code> but still nothing.</p>

<p>Thanks in advance.</p>
