List of usage examples for android.net NetworkCapabilities TRANSPORT_CELLULAR
int TRANSPORT_CELLULAR
To view the source code for android.net NetworkCapabilities TRANSPORT_CELLULAR.
Click Source Link
From source file:com.mobilyzer.util.PhoneUtils.java
public void switchNetwork(boolean toWiFi, CountDownLatch latch) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkRequest.Builder request = new NetworkRequest.Builder(); if (toWiFi) { request.addTransportType(NetworkCapabilities.TRANSPORT_WIFI); } else {/* www .j a v a 2 s . co m*/ request.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR); } request.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET); //// request.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED); // ConnectivityManager.NetworkCallback connectivityNetworkCallback = new ConnectivityNetworkCallback(latch, cm); connectivityNetworkCallback = new ConnectivityNetworkCallback(latch, cm); cm.requestNetwork(request.build(), connectivityNetworkCallback); }