android.net.NetworkRequest

Here are the examples of the java api class android.net.NetworkRequest taken from open source projects.

1. AppService#bringUpCellularNetwork()

Project: Tower
File: AppService.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void bringUpCellularNetwork(Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
        return;
    Timber.i("Setting up cellular network request.");
    final ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkRequest networkReq = new NetworkRequest.Builder().addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR).build();
    connMgr.requestNetwork(networkReq, new ConnectivityManager.NetworkCallback() {

        @Override
        public void onAvailable(Network network) {
            Timber.i("Setting up process default network: %s", network);
            ConnectivityManager.setProcessDefaultNetwork(network);
            DroidPlannerApp.setCellularNetworkAvailability(true);
        }
    });
}