Example usage for android.net NetworkCapabilities TRANSPORT_CELLULAR

List of usage examples for android.net NetworkCapabilities TRANSPORT_CELLULAR

Introduction

In this page you can find the example usage for android.net NetworkCapabilities TRANSPORT_CELLULAR.

Prototype

int TRANSPORT_CELLULAR

To view the source code for android.net NetworkCapabilities TRANSPORT_CELLULAR.

Click Source Link

Document

Indicates this network uses a Cellular transport.

Usage

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);

}